diff --git a/sql/README.md b/sql/README.md index 1dc26d7..61874a9 100644 --- a/sql/README.md +++ b/sql/README.md @@ -117,16 +117,16 @@ single-line comments. ### comment-stacked-dashes -A run of 3 or more consecutive `--` lines must use `/* */` syntax instead. -Up to 2 consecutive `--` lines is fine — a short remark reads fine as `--`. +A run of 2 or more consecutive `--` lines must use `/* */` syntax instead +(or carry an explicit `sql-lint:disable comment-stacked-dashes` exception). +Only a single `--` line is allowed on its own. ```sql -- Bad: stacked dashes --- spanning three +-- spanning two -- or more lines --- Good: 2 lines is fine --- as a short remark +-- Good: a single short remark /* * Good: block comment diff --git a/sql/bin/sql-lint b/sql/bin/sql-lint index 00aa2cb..e9a76d5 100755 --- a/sql/bin/sql-lint +++ b/sql/bin/sql-lint @@ -250,10 +250,10 @@ sub check_stacked_dashes { my @out; my ($start, $end) = (0, 0); - # Up to 2 consecutive -- lines is allowed (a short two-line remark reads - # fine as --); only 3+ must become a /* */ block. + # Only a single -- line is allowed; 2+ consecutive lines must become a + # /* */ block (or carry an explicit sql-lint:disable exception). my $flush = sub { - return unless $start && ($end - $start) >= 2; + return unless $start && ($end - $start) >= 1; my $n = $end - $start + 1; maybe_finding(\@out, $lines, $file, $start, 'comment-stacked-dashes', "$n consecutive -- comment lines ($start-$end); use /* */ for multi-line comments"); diff --git a/sql/test/fixtures/comment-stacked-dashes.bad.sql b/sql/test/fixtures/comment-stacked-dashes.bad.sql index 9b72b35..2d43bbb 100644 --- a/sql/test/fixtures/comment-stacked-dashes.bad.sql +++ b/sql/test/fixtures/comment-stacked-dashes.bad.sql @@ -1,4 +1,4 @@ --- expect-findings: 2 +-- expect-findings: 3 -- This is a multi-line comment -- written with stacked dash lines. -- It should use /* */ instead. @@ -6,3 +6,6 @@ -- This is another -- stacked comment -- spanning three lines. + +-- Even two consecutive lines +-- are no longer allowed. diff --git a/sql/test/fixtures/comment-stacked-dashes.good.sql b/sql/test/fixtures/comment-stacked-dashes.good.sql index 6d14e02..8510a46 100644 --- a/sql/test/fixtures/comment-stacked-dashes.good.sql +++ b/sql/test/fixtures/comment-stacked-dashes.good.sql @@ -2,9 +2,6 @@ -- Another single-line comment, separated by a blank line. --- Two consecutive -- lines are also fine; --- only a run of 3+ must become a /* */ block. - -- /* this is a line comment, not a block comment opening --/* no space variant