Skip to content

chore: local shellcheck gate on edited shell scripts - #2

Open
Chikimuras wants to merge 1 commit into
mainfrom
chore/local-shellcheck-gate
Open

chore: local shellcheck gate on edited shell scripts#2
Chikimuras wants to merge 1 commit into
mainfrom
chore/local-shellcheck-gate

Conversation

@Chikimuras

Copy link
Copy Markdown
Owner

Branche séparée de #1 : ce gate ne dépend d'aucun des correctifs qui s'y trouvent, et il ne touche pas la CI.

Ce que ça fait

Un hook PostToolUse sur Write|Edit lance, sur chaque script shell que Claude écrit ou modifie, exactement le contrôle du job CI shellcheck : shellcheck -S warning -x, dotfiles/ exclu. Un échec sort en code 2, ce qui renvoie le diagnostic dans la session — la faute se voit à l'édition, pas après un push.

Le hook ne fait rien sur autre chose qu'un script shell, ni sur une machine sans shellcheck installé. C'est un confort, pas un substitut à la CI, qui reste le gate qui décide de ce qui se merge.

Vérification

Commande pipe-testée avec la charge stdin réelle du hook (bash -c pour reproduire le process du harness), sur cinq cas :

entrée exit attendu
install/50-stow.sh (sain) 0 0
README.md (non-shell) 0 0
dotfiles/jira/.config/jira-cli/aliases.sh (exclu) 0 0
bootstrap.sh (sans extension .sh) 0 0
script avec un SC2164 2 + diagnostic sur stderr 2

Puis re-testée après écriture, en relisant la commande depuis le JSON (jq -r), pour vérifier que l'échappement du fichier n'a rien cassé. jq -e sur le chemin .hooks.PostToolUse[].hooks[] : OK.

Non vérifié : que le hook se déclenche réellement en session. Il ne peut pas l'être ici — la session courante a pour projet un autre dépôt, donc les settings de forge n'y sont pas chargés. À la prochaine session ouverte dans forge, /hooks permet de le relire, l'éditer ou le désactiver.

🤖 Generated with Claude Code

Runs the same check the CI shellcheck job runs (-S warning -x, dotfiles/
excluded) on every shell script Claude writes or edits, so a lint failure
surfaces at edit time rather than after a push. Exit 2 feeds shellcheck's
diagnostic back into the session.

No-ops on anything that is not a shell script, and on machines without
shellcheck installed — it is a convenience, not a substitute for the CI
job, which stays the gate that decides what merges.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 3, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The added hook command has a couple of correctness/robustness issues (dotfiles exclusion matching and missing jq presence guard) that can cause unexpected behavior during edits.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a Claude Code local hook configuration to run the same shellcheck invocation as CI whenever Claude writes/edits shell scripts, surfacing diagnostics immediately during editing (without changing CI behavior).

Changes:

  • Introduces .claude/settings.json with a PostToolUse hook on Write|Edit.
  • Runs shellcheck -S warning -x on edited *.sh scripts (with an intended exclusion for dotfiles/), and returns exit code 2 on failure.
File summaries
File Description
.claude/settings.json Adds a Claude Code PostToolUse hook that runs shellcheck on edited shell scripts to catch issues at edit-time.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .claude/settings.json
"hooks": [
{
"type": "command",
"command": "jq -r \"(.tool_response.filePath // .tool_input.file_path) // empty\" | { read -r f || exit 0; case \"$f\" in */dotfiles/*) exit 0 ;; *.sh|*/bootstrap.sh) ;; *) exit 0 ;; esac; command -v shellcheck >/dev/null || exit 0; shellcheck -S warning -x \"$f\" >&2 || exit 2; }",
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.

2 participants