fix: ZC1075 skips bare expansions of arrays#1422
Merged
Merged
Conversation
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
approved these changes
Jun 25, 2026
redteamx
left a comment
Collaborator
There was a problem hiding this comment.
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.
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
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
$arras"$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:
name=(…)array literals,local -a/typeset -A/declare -a/readonly -adeclarations, andlocal opts=(…)).$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
$1asname=($1)(spurious parens), so a string-based=(check would misclassify scalars as arrays. The harvest inspects the parsed value node (anArrayLiteralpart) and the declaration flags instead, so a scalarlocal worker=$1is 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=$1still fires).Verification
async.zsh,zsh-vi-mode,gitstatus) — every removed expansion names a genuinely array-declared variable.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-lint0 issues,gocycloclean, the new harvest helpers are 100% covered, fix-corpus sweep stays clean.