Skip to content

fix: ZC1075 skips flag-led expansions#1421

Merged
afadesigns merged 1 commit into
mainfrom
fix/zc1075-flag-led
Jun 25, 2026
Merged

fix: ZC1075 skips flag-led expansions#1421
afadesigns merged 1 commit into
mainfrom
fix/zc1075-flag-led

Conversation

@afadesigns

Copy link
Copy Markdown
Owner

What

Stop ZC1075 ("quote this expansion") from flagging a flag-led parameter expansion the parser cannot fully model.

${(%):-default} parses to an expansion with a % flag, a nil subject (Left), and ${ } as rendered text — the parser drops the :-default. ZC1075 then flagged it as an elision hazard. But a (%) prompt expansion with a :- default never yields an empty word, so the advice is wrong.

When the parser could not resolve the subject (Left is nil), ZC1075 now skips the expansion instead of guessing.

Why

The flagged forms (${(%):-…}, ${(P)…}) carry a default or width modifier that guarantees a non-empty result, so quoting against elision is meaningless. Without the parsed subject, the kata has no basis to judge elision, so skipping is the conservative correct choice. Confirmed against real zsh: ${(%):-fallback} always prints fallback.

Verification

  • Flag-led forms now skip; ordinary scalars ($plain) and array elements (${arr[1]}) still fire; normal ${var:-default} and split flags ${(f)x} keep their existing skips.
  • Removes 1 finding from the violation baseline (zinit, read -q ${(%):-"?…"}).
  • Regression test in pkg/katas/katatests/fp_round7_test.go; go test ./... passes, golangci-lint 0 issues, sweeps clean.

A flag-led parameter expansion such as `${(%):-default}` or `${(P)…}`
carries a flag plus a default that the parser cannot resolve to a
subject, so it leaves the expansion's Left nil and `${ }` as the rendered
text. ZC1075 then flagged it as an elision hazard, but a `(%)` prompt
expansion with a `:-` default never produces an empty word, so the
"quote it" advice is wrong.

When the parser could not resolve the expansion subject (Left is nil),
ZC1075 now skips it rather than guessing. Ordinary scalars and array
elements still fire. Removes 1 finding from the violation baseline
(zinit); regression test added.

@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. Flag-led-expansion FP confirmed; nil-subject skip, baseline drift reviewed (zinit ${(%):-} prompt-default), regression test added.

@github-actions github-actions Bot added ci CI/CD and workflow changes test Adding or correcting tests area/katas pkg/katas — detection logic labels Jun 25, 2026
@afadesigns afadesigns merged commit 536ec51 into main Jun 25, 2026
19 checks passed
@afadesigns afadesigns deleted the fix/zc1075-flag-led branch June 25, 2026 20:38
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 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