mirror of
https://github.com/aaddrick/claude-desktop-debian.git
synced 2026-05-17 08:36:35 +03:00
feat: expand lint hook to git push, add /lint skill
- Change PreToolUse lint hook from gh pr create to git push - Add /lint skill for manual linting (available to Claude and user) - Add linting guidance to CLAUDE.md (fix issues, disable directives as last resort) Co-Authored-By: Claude <claude@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# PreToolUse hook: Run shellcheck and actionlint before PR creation
|
||||
# PreToolUse hook: Run shellcheck and actionlint before git push
|
||||
#
|
||||
# Checks shell scripts and GitHub Actions workflows for issues
|
||||
# before allowing gh pr create to proceed.
|
||||
# before allowing git push to proceed.
|
||||
|
||||
set -o pipefail
|
||||
|
||||
@@ -19,8 +19,8 @@ if [[ "$tool_name" != 'Bash' ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Only process gh pr create commands
|
||||
if [[ "$command" != *'gh pr create'* ]]; then
|
||||
# Only process git push commands
|
||||
if [[ "$command" != *'git push'* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -77,9 +77,9 @@ if [[ -n "$changed_workflows" ]]; then
|
||||
check_actionlint "$changed_workflows"
|
||||
fi
|
||||
|
||||
# If errors found, block the PR creation
|
||||
# If errors found, block the push
|
||||
if [[ -n "$errors" ]]; then
|
||||
printf '%s\n' 'Lint checks failed. Fix these issues before creating the PR:' >&2
|
||||
printf '%s\n' 'Lint checks failed. Fix these issues before pushing:' >&2
|
||||
printf '\n%s' "$errors" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
53
.claude/skills/lint/SKILL.md
Normal file
53
.claude/skills/lint/SKILL.md
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
name: lint
|
||||
description: Run shellcheck and actionlint on shell scripts and GitHub Actions workflows. Use before pushing or when fixing lint issues.
|
||||
---
|
||||
|
||||
Run linting tools on shell scripts and GitHub Actions workflows in this project.
|
||||
|
||||
## Your Task
|
||||
|
||||
Run the following checks on changed files (relative to main branch):
|
||||
|
||||
### 1. Shell Scripts (shellcheck)
|
||||
|
||||
```bash
|
||||
# Find changed shell scripts
|
||||
changed_scripts=$(git diff --name-only main...HEAD 2>/dev/null | grep -E '\.sh$')
|
||||
|
||||
# Run shellcheck on each
|
||||
for script in $changed_scripts; do
|
||||
if [[ -f "$script" ]]; then
|
||||
shellcheck -f gcc "$script"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
### 2. GitHub Actions Workflows (actionlint)
|
||||
|
||||
```bash
|
||||
# Find changed workflow files
|
||||
changed_workflows=$(git diff --name-only main...HEAD 2>/dev/null | grep -E '\.github/workflows/.*\.ya?ml$')
|
||||
|
||||
# Run actionlint on each
|
||||
for workflow in $changed_workflows; do
|
||||
if [[ -f "$workflow" ]]; then
|
||||
actionlint "$workflow"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
## Handling Issues
|
||||
|
||||
When lint issues are found:
|
||||
|
||||
1. **Fix the issues** - Correct the code to resolve warnings/errors
|
||||
2. **Only use disable directives as a last resort** - If a warning is a false positive or truly unavoidable, add a disable comment with explanation:
|
||||
```bash
|
||||
# shellcheck disable=SC2034 # Variable used by sourcing script
|
||||
```
|
||||
3. **Report what was fixed** - Summarize the changes made
|
||||
|
||||
## Optional Guidance
|
||||
|
||||
$ARGUMENTS
|
||||
11
CLAUDE.md
11
CLAUDE.md
@@ -14,6 +14,17 @@ All shell scripts in this project must follow the [Bash Style Guide](STYLEGUIDE.
|
||||
- Lowercase variables; UPPERCASE only for constants/exports
|
||||
- Use `local` in functions, avoid `set -e` and `eval`
|
||||
|
||||
### Linting
|
||||
|
||||
Shell scripts are checked with `shellcheck` and GitHub Actions workflows with `actionlint` before pushing. When lint issues are found:
|
||||
|
||||
1. **Fix the code** - Correct the underlying issue rather than suppressing the warning
|
||||
2. **Disable directives are a last resort** - Only use `# shellcheck disable=SCXXXX` when:
|
||||
- The warning is a false positive
|
||||
- The pattern is intentional and unavoidable
|
||||
- Always add a comment explaining why the disable is needed
|
||||
3. **Run `/lint` to check manually** - Use this skill to check for issues before pushing
|
||||
|
||||
## GitHub Workflow
|
||||
|
||||
### General Approach
|
||||
|
||||
Reference in New Issue
Block a user