Skip to content

fix: lint inside logical-chain compound bodies#1426

Merged
afadesigns merged 1 commit into
mainfrom
fix/lint-logical-chain-compound-bodies
Jun 25, 2026
Merged

fix: lint inside logical-chain compound bodies#1426
afadesigns merged 1 commit into
mainfrom
fix/lint-logical-chain-compound-bodies

Conversation

@afadesigns

Copy link
Copy Markdown
Owner

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: keywordStmtToExpression wrapped the compound in a stub identifier, 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 the fix returns the real node, exactly as the while head already does.

Latent false positives surfaced by the wider coverage, fixed here:

  • ZC1071 fired on a single-element rebuild (arr=(${arr[@]:#p}), a filter, not an append). Now requires 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. Parser-error sweep stays 402/0; fix-corpus sweep clean; full suite, gocyclo, and golangci-lint green.

Tests: TestParseLogicalChainCompoundBodyWalked (parser), TestLogicalChainCompoundBodyLinted plus per-kata FP regressions in fp_round10_test.go.

Severity: mixed (false negatives closed, false positives removed).

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>
@github-actions github-actions Bot added ci CI/CD and workflow changes test Adding or correcting tests area/parser pkg/lexer + pkg/parser + pkg/ast area/katas pkg/katas — detection logic labels Jun 25, 2026

@redteamx redteamx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on review.

@afadesigns afadesigns merged commit a55b590 into main Jun 25, 2026
19 checks passed
@afadesigns afadesigns deleted the fix/lint-logical-chain-compound-bodies branch June 25, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/katas pkg/katas — detection logic area/parser pkg/lexer + pkg/parser + pkg/ast ci CI/CD and workflow changes test Adding or correcting tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants