diff --git a/scripts/check-comment-blocks.sh b/scripts/check-comment-blocks.sh index c3b90fe6..94da77cf 100755 --- a/scripts/check-comment-blocks.sh +++ b/scripts/check-comment-blocks.sh @@ -11,8 +11,8 @@ # # Scope: tracked *.rs *.nix *.sh *.js *.ts *.css *.html. Markdown is exempt # (it is prose by nature). Comment forms: `#` line comments (nix/sh), `//` -# line comments (rs/js/ts), and `/* */` (rs/js/ts/css) + `` (html) -# block comments. A blank line separates two line-comment blocks (does NOT +# line comments (rs/js/ts), and `/* */` block comments (nix/rs/js/ts/css) + +# `` (html). A blank line separates two line-comment blocks (does NOT # extend a run); a blank inside a `/* */` / `` block stays part of it. # # Escape hatch: a `lint:allow-long-comment` marker anywhere in a block @@ -27,7 +27,8 @@ hits="$( git ls-files -z '*.rs' '*.nix' '*.sh' '*.js' '*.ts' '*.css' '*.html' \ | xargs -0 -r awk -v MAX="$MAX" ' function mode_of(fn) { - if (fn ~ /\.(nix|sh)$/) return "hash" + if (fn ~ /\.nix$/) return "nix" + if (fn ~ /\.sh$/) return "hash" if (fn ~ /\.(rs|js|ts)$/) return "slash" if (fn ~ /\.css$/) return "cstyle" if (fn ~ /\.html$/) return "html" @@ -47,6 +48,10 @@ hits="$( if (index($0, blockend) > 0) inblock = 0 } else if (mode == "hash") { if ($0 ~ /^[ \t]*#/) c = 1 + } else if (mode == "nix") { + # nix: `#` line comments AND `/* */` block comments. + if ($0 ~ /^[ \t]*#/) c = 1 + else if ($0 ~ /^[ \t]*\/\*/) { c = 1; if (index($0, "*/") == 0) { inblock = 1; blockend = "*/" } } } else if (mode == "slash") { if ($0 ~ /^[ \t]*\/\//) c = 1 else if ($0 ~ /^[ \t]*\/\*/) { c = 1; if (index($0, "*/") == 0) { inblock = 1; blockend = "*/" } }