fix(lint): check the syntax of every shell source #69
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/lint-checks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
make lintis the check every contributor and agent runs before eachcommit: a Bash syntax check of the project's 53 shell sources, then
ShellCheck where it is installed. On a host without ShellCheck it
passed a source with a syntax error, because the syntax check read
bin/azkabanalone:bash -n FILE FILE...parses its first file andtakes the others as that script's arguments. ShellCheck reports the
same error where it runs, which kept the defect out of sight in the
project's images.
The ShellCheck pass was also the slowest step of every commit: one
process for all the sources, about 11 s on a 20-CPU host, against 6 s
for the whole test suite.
Set aside: dropping
bash -nand relying on ShellCheck, since therecipe skips ShellCheck where it is missing; and keeping ShellCheck's
default multi-line reports in the parallel run, which interleave on a
terminal when several files have findings.
What changed
Before, a syntax error in any source but the first passed the lint on a
host without ShellCheck. Now the lint parses every source, reports each
error with its file and line, and fails.
Before, ShellCheck checked the sources one after another. Now one
process per CPU checks them, with the same findings and exit status in
about a third of the time, and each finding is one line in ShellCheck's
gcc format,
file:line:column: note: text [SC2086]. The snippet andthe suggested fix are a
shellcheck <file>away.The change is the
lintrecipe of theMakefileand two tests intests/unit/test_containerfile.sh. Not in this change: the Verifycommand still runs ShellCheck a second time through
.agents/hooks/shellcheck.sh repo, which comes from Agent Foundry.How to verify
Have Git, GNU Make, Bash 4.4 or newer, and ShellCheck, on Linux or
macOS. No container engine is needed.
The syntax check, on a
PATHwithout ShellCheck:On
masterit printsshellcheck not installed; skippedandexit 0.After
git switch fix/lint-checksthe same last line printsbroken.sh: line 1: syntax error near unexpected token `then'andexit 2.The parallel pass, with ShellCheck on the
PATH:On a 20-CPU host
time make linttook 11.3 s onmasterand 3.5 s onthe branch. The second command prints, on the branch,
finding.sh:2:6: note: Double quote to prevent globbing and word splitting. [SC2086]and
exit 2.Checks run on the tip:
make lint && .agents/hooks/shellcheck.sh repo && make testpasses, 354 tests. The new test
test_make_lint_fails_on_a_syntax_error_in_any_source_without_shellcheckfails on
master; the pintest_make_lint_fails_on_a_shellcheck_finding_in_any_sourcepasses onboth. Not tried: BSD
xargson macOS, which documents the-Ptherecipe uses.
Considerations
A passing
make lintnow prints nothing, where it echoed thebash -ncommand.
xargs -Pis outside POSIX; GNU and BSDxargsboth take it.