fix: lint inside logical-chain compound bodies#1426
Merged
Conversation
A compound statement on the right of a `&&` / `||` chain
(`cmd && { ... }`, `cmd && if ...; fi`, `cmd && for ...; done`,
`cmd && case ... esac`) was wrapped in a stub identifier by
keywordStmtToExpression, so the AST walker never descended into
the body. Dangerous code inside the block, such as an unquoted
`rm -rf $x`, went unlinted. These statement types already
implement Expression, so return the real node, as the WHILE head
already does; the walker now walks the body.
Walking the bodies surfaced four latent kata false positives,
fixed here:
- ZC1071 fired on a single-element rebuild (`arr=(${arr[@]:#p})`,
a filter, not an append). Require the whole-array reference plus
at least one appended element.
- ZC1075 fired on a `$var` glued to a literal command-name prefix
(`_clear$fsuf`), which cannot elide the word.
- ZC1075 fired on a `(q)`-quoted expansion, which renders an empty
value as a quoted empty string and never elides.
- ZC1149 fired on an error message already routed to stderr
(`print -u2`, `>&2`).
Net corpus effect: 28 real findings inside compound bodies now
visible; 21 false positives removed.
Signed-off-by: afadesigns <afadesign.official@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: a compound statement on the right of a
&&/||chain (cmd && { ... },cmd && if ...; fi,cmd && for ...; done,cmd && case ... esac) is now walked, so katas see the code inside the block.Why:
keywordStmtToExpressionwrapped the compound in a stub identifier, so the AST walker never descended into the body. Dangerous code inside the block, such as an unquotedrm -rf $x, went unlinted. These statement types already implementExpression, so the fix returns the real node, exactly as thewhilehead already does.Latent false positives surfaced by the wider coverage, fixed here:
arr=(${arr[@]:#p}), a filter, not an append). Now requires the whole-array reference plus at least one appended element.$varglued to a literal command-name prefix (_clear$fsuf), which cannot elide the word.(q)-quoted expansion, which renders an empty value as a quoted empty string and never elides.print -u2,>&2).Net corpus effect: 28 real findings inside compound bodies now visible; 21 false positives removed. Parser-error sweep stays 402/0; fix-corpus sweep clean; full suite, gocyclo, and golangci-lint green.
Tests:
TestParseLogicalChainCompoundBodyWalked(parser),TestLogicalChainCompoundBodyLintedplus per-kata FP regressions infp_round10_test.go.Severity: mixed (false negatives closed, false positives removed).