But it does not work when using continuation lines:
$ if [ -f foo.txt ]; then
> echo "file exists"; fi
I could craft a simple script to parse these lines, but I wonder if there’s a simpler integrated solution: either a way for Dune to output the list of commands to be run (so I could pass it to shellcheck), or some sort of “Cram linter”?
------ example/hello_world.t/run.t
++++++ example/hello_world.t/run.t.corrected
File "example/hello_world.t/run.t", line 12, characters 0-1:
| $ checked_sh() (
| > script=$(cat) || exit
| > printf '%s\n' "$script" | shellcheck --shell=sh - &&
| > printf '%s\n' "$script" | sh
| > )
|
| $ cat <<'SH' | checked_sh
| > name='world'
| > bar='unused'
| > printf 'Hello, %s!\n' "$name"
| > SH
+|
+| In - line 2:
+| bar='unused'
+| ^-^ SC2034 (warning): bar appears unused. Verify use (or export if used externally).
+|
+| For more information:
+| https://www.shellcheck.net/wiki/SC2034 -- bar appears unused. Verify use (o...
+| [1]
Neither option is super clean, tho, is it?
You might consider opening an issues on Issues · ocaml/dune · GitHub to propose some sort of support for configuring a linting check (or a more general preprocessor?) be added to the stanza for Cram - Dune documentation . Core devs may then be able to opine other ways of addressing this and on the likelihood of such a feature request.