Skip to content

fix: ZC1075 skips bare expansions of arrays#1422

Merged
afadesigns merged 1 commit into
mainfrom
fix/zc1075-array-quoting
Jun 25, 2026
Merged

fix: ZC1075 skips bare expansions of arrays#1422
afadesigns merged 1 commit into
mainfrom
fix/zc1075-array-quoting

Conversation

@afadesigns

Copy link
Copy Markdown
Owner

What

Stop ZC1075 from flagging a bare expansion of a variable that holds an array. The kata's premise — an unquoted empty value elides and drops the word — is a scalar concern. For an array, quoting $arr as "$arr" joins the elements into one word; the correct form is "${arr[@]}", which the message already states.

ZC1075 moves from a per-command check to a program-level one:

  1. Harvest every array name in the file (from name=(…) array literals, local -a/typeset -A/declare -a/readonly -a declarations, and local opts=(…)).
  2. Flag only bare scalar expansions; skip a bare $arr / ${arr} whose name was harvested as an array.

Why this is careful

Array detection reads the AST, not rendered text. The renderer prints a scalar value $1 as name=($1) (spurious parens), so a string-based =( check would misclassify scalars as arrays. The harvest inspects the parsed value node (an ArrayLiteral part) and the declaration flags instead, so a scalar local worker=$1 is never mistaken for an array.

This was prototyped, found to over-suppress via the renderer trap, reverted, and re-done against the AST — the over-suppression is gone (local worker=$1 still fires).

Verification

  • Removes 121 findings across 33 corpora; spot-checked the harvested set in the biggest-drop files (async.zsh, zsh-vi-mode, gitstatus) — every removed expansion names a genuinely array-declared variable.
  • Scalars (local worker=$1, local x=$(cmd), rm $file), array elements ${arr[i]}, and the flag-led / default-modifier skips are all unchanged.
  • go test ./... passes, golangci-lint 0 issues, gocyclo clean, the new harvest helpers are 100% covered, fix-corpus sweep stays clean.

A bare `$arr` where `arr` holds an array does not elide the way a scalar
does — quoting it as `"$arr"` joins the elements into one word, so the
elision advice was wrong (the right form is `"${arr[@]}"`). The kata now
recognises arrays and skips them.

ZC1075 moves from a per-command check to a program-level one: it first
harvests every array name in the file, then flags only bare scalar
expansions. Arrays are read from the AST, not rendered text, because the
renderer prints a scalar value `$1` as `name=($1)` — array detection
inspects the parsed value node (an `ArrayLiteral`) and the `-a`/`-A`
declaration flags, so a scalar `local worker=$1` is never mistaken for an
array.

Removes 121 findings from the violation baseline across 33 corpora; every
removed bare expansion names a variable declared `local -a` / `typeset
-A` / `name=(…)`. Scalars, array elements `${arr[i]}`, and the existing
flag-led and default-modifier skips are unchanged. Regression and
helper-coverage tests 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.

@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

@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. ZC1075 array rework: AST-based harvest (avoids the renderer paren trap), over-suppression verified gone, 121 baseline removals spot-checked, helpers 100% covered.

@afadesigns afadesigns merged commit 510c16a into main Jun 25, 2026
18 checks passed
@afadesigns afadesigns deleted the fix/zc1075-array-quoting branch June 25, 2026 21:17
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