Skip to content

chore: Add diff-only RuboCop wrapper script (WA-VERIFY-029)#1010

Open
kitcommerce wants to merge 2 commits intonextfrom
issue-871-rubocop-diff-script
Open

chore: Add diff-only RuboCop wrapper script (WA-VERIFY-029)#1010
kitcommerce wants to merge 2 commits intonextfrom
issue-871-rubocop-diff-script

Conversation

@kitcommerce
Copy link
Contributor

Summary

Adds script/rubocop_diff, a lightweight shell script that runs RuboCop only on the Ruby/Rails files changed versus a configurable base ref. This avoids the cost of linting the entire codebase during local development and CI pre-checks.

Features

  • Configurable base ref — defaults to origin/next; overridable via first positional argument or $RUBOCOP_DIFF_BASE env var.
  • Targeted file detection — uses git diff --name-only --diff-filter=ACMR restricted to *.rb, *.rake, and *.ru files.
  • No-op when nothing changed — prints No Ruby changes detected and exits 0.
  • Clear PASS/FAIL summary — human-readable output with file count and RuboCop exit code propagated.
  • Read-only — never mutates any file.
  • POSIX-safe path resolutioncd to repo root so it works from any working directory.
  • Follows existing script/ conventions (shebang, set -euo pipefail, header comment block).

Usage

# Default: compare vs origin/next
./script/rubocop_diff

# Override base ref via argument
./script/rubocop_diff origin/main

# Override via environment variable
RUBOCOP_DIFF_BASE=main ./script/rubocop_diff

Verification

Confirm FAIL on known offense

# In a branch with a changed .rb file containing a RuboCop offense:
./script/rubocop_diff
# → FAIL — RuboCop reported offenses in changed file(s). Exit code: 1
echo $?   # 1

Confirm PASS after fixing offense

# After correcting the offense:
./script/rubocop_diff
# → PASS — RuboCop found no offenses in N changed file(s).
echo $?   # 0

Confirm no-op when no Ruby files changed

# On a branch that only touched non-Ruby files:
./script/rubocop_diff
# → No Ruby changes detected vs origin/next.
echo $?   # 0

Closes #871

@kitcommerce kitcommerce added the gate:build-failed Build gate failed label Mar 16, 2026
@kitcommerce
Copy link
Contributor Author

Build gate failed — ShellCheck SC2001

script/rubocop_diff line 84:

echo "$CHANGED_FILES" | sed 's/^/  /'

ShellCheck SC2001 (style): Use ${variable//search/replace} instead of sed.

Fix: Replace the sed call with shell parameter expansion:

printf '%s\n' "$CHANGED_FILES" | while IFS= read -r line; do printf '  %s\n' "$line"; done
# OR simply:
echo "${CHANGED_FILES//$'\n'/$'\n  '}"

Or the simplest fix — use printf with indentation directly. The key is avoiding sed for simple prefix operations that ShellCheck SC2001 flags.

Please push a fix to the branch.

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

Labels

gate:build-failed Build gate failed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant