aboutsummaryrefslogtreecommitdiff
path: root/scripts/lint.sh
blob: 2956affb1adc9981565a424919e90b44bf92ca8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# Validate ruleset structure. Runs from the rulesets repo root.
# Checks:
#   - Every .md rule file starts with a top-level heading
#   - Every rule file has an 'Applies to:' header
#   - Every language CLAUDE.md has a top-level heading
#   - Every hook script has a shebang and is executable

set -u

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"

errors=0

warn() {
  printf '  WARN: %s\n' "$1"
  errors=$((errors + 1))
}

check_md_heading() {
  local f="$1"
  [ -f "$f" ] || return 0
  if ! head -1 "$f" | grep -q '^# '; then
    warn "$f — missing top-level heading"
  fi
}

check_md_applies_to() {
  local f="$1"
  [ -f "$f" ] || return 0
  if ! grep -q '^Applies to:' "$f"; then
    warn "$f — missing 'Applies to:' header"
  fi
}

check_hook() {
  local f="$1"
  [ -f "$f" ] || return 0
  if ! head -1 "$f" | grep -q '^#!'; then
    warn "$f — missing shebang"
  fi
  if [ ! -x "$f" ]; then
    warn "$f — not executable (chmod +x)"
  fi
}

echo "Linting rulesets in $REPO_ROOT"

# Generic rules
for f in claude-rules/*.md; do
  [ -f "$f" ] || continue
  check_md_heading "$f"
  check_md_applies_to "$f"
done

# Per-language rule files
for rules_dir in languages/*/claude/rules; do
  [ -d "$rules_dir" ] || continue
  for f in "$rules_dir"/*.md; do
    [ -f "$f" ] || continue
    check_md_heading "$f"
    check_md_applies_to "$f"
  done
done

# Per-language CLAUDE.md templates
for claude_md in languages/*/CLAUDE.md; do
  [ -f "$claude_md" ] || continue
  check_md_heading "$claude_md"
done

# Hook scripts
for h in languages/*/claude/hooks/*.sh languages/*/githooks/*; do
  [ -f "$h" ] || continue
  check_hook "$h"
done

# Shared install/diff/lint scripts (sanity check)
for s in scripts/*.sh; do
  [ -f "$s" ] || continue
  check_hook "$s"
done

echo "---"
if [ "$errors" -eq 0 ]; then
  echo "All checks passed."
else
  echo "$errors warning(s)."
  exit 1
fi