Skip to content

SonarCloud: shell script hygiene cleanup (×20) #370

Closed

Description

@don-petry

Shell script hygiene cleanup

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

Findings

Rule Count Representative message
shelldre:S7688 19 Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more featur
shelldre:S7682 1 Add an explicit return statement at the end of the function.

Affected files

  • scripts/apply-rulesets.sh (8)
  • scripts/apply-repo-settings.sh (7)
  • tests/scripts/apply-repo-settings.test.sh (5)

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
    ContributorAuthor

    Dev-Lead Implementation Plan

    Issue: #370 — SonarCloud: shell script hygiene cleanup (×20)

    Scope

    Behavior-preserving shell hygiene: replace 19 [ ... ] POSIX tests with [[ ... ]] (S7688) and add one explicit return to the assert_contains function (S7682), across the three affected scripts.

    Implementation Checklist

    • scripts/apply-rulesets.sh — convert 8 [ ... ] tests → [[ ... ]]
    • scripts/apply-repo-settings.sh — convert 7 [ ... ] tests → [[ ... ]]
    • tests/scripts/apply-repo-settings.test.sh — convert 4 [ ... ] tests → [[ ... ]] and add explicit return to assert_contains

    Tests to Write

    • No new tests: pure behavior-preserving refactor. Existing suite tests/scripts/apply-repo-settings.test.sh (runs the script in --dry-run --force) is the regression guard and must stay green.

    Test Command

    bash tests/scripts/apply-repo-settings.test.sh

  2. don-petry commented on Jul 3, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead: Implementation Complete

    Plan Execution

    • scripts/apply-rulesets.sh — converted 8 [ ... ] tests → [[ ... ]] (S7688)
    • scripts/apply-repo-settings.sh — converted 7 [ ... ] tests → [[ ... ]] (S7688)
    • tests/scripts/apply-repo-settings.test.sh — converted 4 [ ... ] tests → [[ ... ]] (S7688) and added explicit return 0 to assert_contains (S7682)

    Total: 19 × S7688 + 1 × S7682 = 20 findings addressed. All fixes are real (no NOSONAR).

    Test Results

    $ bash tests/scripts/apply-repo-settings.test.sh
    ok - enforces secret_scanning
    ok - enforces secret_scanning_push_protection
    ok - enforces secret_scanning_ai_detection
    ok - enforces secret_scanning_non_provider_patterns
    ok - sets security_and_analysis status to enabled
    ok - enforces vulnerability-alerts
    ok - enforces automated-security-fixes
    ---
    PASS — 7 assertion(s) passed
    
    $ shellcheck scripts/apply-rulesets.sh scripts/apply-repo-settings.sh tests/scripts/apply-repo-settings.test.sh
    (clean)
    
    $ bash .dev-lead/scripts/dev-lead-lint.sh
    [lint] all checks passed
    

    Files Changed

    • scripts/apply-rulesets.sh: 8 conditional tests [ ] → [[ ]]
    • scripts/apply-repo-settings.sh: 7 conditional tests [ ] → [[ ]]
    • tests/scripts/apply-repo-settings.test.sh: 4 conditional tests [ ] → [[ ]]; explicit return 0 added to assert_contains

    Notes

    Pure behavior-preserving refactor, so Phase 2 (test-first) was handled per the documented exception — the existing regression test (--dry-run --force) is the guard and stays green. All =/!= comparisons use quoted or literal operands, so [[ ]] pattern-matching semantics do not alter behavior. assert_contains return value is unused by callers, so return 0 is a no-op behaviorally. No unrelated files touched (.dev-lead/scripts/apply-repo-settings.sh copy left untouched — not in scope).

  3. added a commit that references this issue on Jul 3, 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