Skip to content

SonarCloud: shell script hygiene cleanup (×24) #420

Closed

Description

@don-petry

Shell script hygiene cleanup

SonarCloud open findings in petry-projects/google-app-scripts — 24 issue(s) grouped as one workstream. Part of the org SonarCloud tuning initiative combsmith/.github#593.

Findings

Rule Count Representative message
shelldre:S7688 17 Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more featur
shelldre:S7677 7 Redirect this error message to stderr (>&2).

Affected files

  • scripts/setup-dependabot-app.sh (12)
  • scripts/setup-pr-quality-ruleset.sh (5)
  • scripts/setup-code-quality-ruleset.sh (4)
  • scripts/apply-repo-settings.sh (3)

Approach

Mechanical, per-file: [ → [[ (S7688), redirect errors to stderr >&2 (S7677), add explicit return/final statement (S7682), assign positional params to local vars (S7679), replace repeated string literals with a constant (S1192). Behavior unchanged; run script tests after.

Acceptance

  • All listed SonarCloud findings for this repo/workstream resolved to zero
  • No behavior change; existing tests/CI green
  • Fixes are real (no blanket NOSONAR unless a confirmed false positive, noted inline)

Filed from the 2026-07-03 org SonarCloud review.

Activity

  1. don-petry commented on Jul 3, 2026

    @don-petry
    CollaboratorAuthor

    Dev-Lead Implementation Plan

    Issue: #420 — SonarCloud: shell script hygiene cleanup (×24)

    Scope

    Mechanically resolve 24 SonarCloud shell findings across 4 scripts: convert 17 [ ... ] POSIX tests to [[ ... ]] (S7688) and redirect 7 Error: messages (plus their same-block usage/continuation lines) to stderr with >&2 (S7677). Behavior preserved.

    Implementation Checklist

    • scripts/setup-dependabot-app.sh — 9× [→[[; stderr on Error: $cmd, Error: gh not authenticated, Error: Private key… (+ its continuation + Usage)
    • scripts/setup-pr-quality-ruleset.sh — 3× [→[[; stderr on Error: gh CLI…, Error: gh not authenticated (+ Usage)
    • scripts/setup-code-quality-ruleset.sh — 3× [→[[; stderr on Error: gh not authenticated (+ Usage)
    • scripts/apply-repo-settings.sh — 2× [→[[; stderr on Error: gh not authenticated (+ Usage)

    Tests to Write

    • None. No shell-script test suite exists in this repo; this is a behavior-preserving refactor (Phase 2 TDD exception). Verification is via shellcheck + existing Jest suite (unaffected).

    Test Command

    npm test (Jest, unaffected) and bash .dev-lead/scripts/dev-lead-lint.sh (shellcheck)

  2. don-petry commented on Jul 3, 2026

    @don-petry
    CollaboratorAuthor

    Dev-Lead: Implementation Complete

    Plan Execution

    • scripts/setup-dependabot-app.sh — 9× [→[[, Error:/usage-exit paths → >&2
    • scripts/setup-pr-quality-ruleset.sh — 3× [→[[, 2× Error: + usage → >&2
    • scripts/setup-code-quality-ruleset.sh — 3× [→[[, Error: + usage → >&2
    • scripts/apply-repo-settings.sh — 2× [→[[, Error: + usage → >&2

    Resolves all 24 findings: 17× S7688 ([→[[) + 7× S7677 (Error: messages → stderr).

    Test Results

    > jest --runInBand
    
    Test Suites: 12 passed, 12 total
    Tests:       301 passed, 301 total
    Snapshots:   0 total
    Time:        4.811 s
    Ran all test suites.
    
    # shellcheck (dev-lead-lint.sh): 4 file(s), all checks passed
    # npm run check (prettier --check + eslint): 0 errors (22 pre-existing warnings in unrelated Jest test files)
    

    Files Changed

    • scripts/setup-dependabot-app.sh: 9 conditional tests [→[[; redirected Error: (×3) + its continuation + Usage: to stderr
    • scripts/setup-pr-quality-ruleset.sh: 3 conditional tests [→[[; redirected Error: (×2) + Usage: to stderr
    • scripts/setup-code-quality-ruleset.sh: 3 conditional tests [→[[; redirected Error: + Usage: to stderr
    • scripts/apply-repo-settings.sh: 2 conditional tests [→[[; redirected Error: + Usage: to stderr

    Notes

    • No shell-script test suite exists in this repo, so Phase 2 (TDD) was skipped per the behavior-preserving-refactor exception. Verification was done via shellcheck --severity=warning and the existing Jest suite (301 tests, unaffected).
    • Beyond the 7 SonarCloud-flagged Error: lines, I also redirected the same-block Usage:-before-exit 1 messages and the multi-line "Private key not found" continuation to stderr, so each error-exit path is fully on stderr rather than split across stdout/stderr. This is consistent, standard-Unix hygiene and introduces no new findings.
    • Behavior otherwise unchanged: [[ ... ]] preserves the original quoted-string/file-test semantics; = comparison stays a literal string match (RHS quoted).
  3. added a commit that references this issue on Jul 4, 2026
  4. added a commit that references this issue on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev-leadFor dev-lead agent pickupenhancementFeature requests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions