When to Use This Skill
| Use this skill when... |
Use something else instead when... |
| Running a parallel anti-pattern scan and producing a report |
Looking up the full YAML rule catalog → see REFERENCE.md |
Specifically targeting empty catches, floating promises, or || true |
Use the dedicated scanner → code-hidden-failures --track errors |
| Finding success-on-empty / silent degradation patterns |
Use the dedicated scanner → code-hidden-failures --track degradation |
| Broad code-quality review across security, perf, and architecture |
Run the full review delegate → code-review |
Context
- Analysis path:
$1 (defaults to current directory if not specified)
- JS/TS files: !
find . -type f \( -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" \)
- Vue files: !
find . -name "*.vue"
- Python files: !
find . -name "*.py"
Your Task
Perform comprehensive anti-pattern analysis. The mechanical detection is one
deterministic ast-grep scan over a shipped rule project — you do not re-type
sg -p '…' patterns and do not fan out agents just to run them. Your job is
the judgment: severity triage, recommendations, and fix planning on top of the
scan's structured findings.
Step 1: Run the deterministic scan
The detection catalog lives as an ast-grep rule project in
rules/ (one *.yml per pattern under rules/lib/, each with a
valid/invalid test fixture in rules/tests/). Run the whole catalog in one pass:
ast-grep scan -c ${CLAUDE_SKILL_DIR}/rules/sgconfig.yml --json=compact <path>
Each JSON finding carries ruleId, file, range (line/column), message, and
the matched text. Parse this — it is the raw finding set for every category
below. The rules cover: empty catch, console.log, var, eval/new Function,
innerHTML/outerHTML, as any / : any annotations, magic-number timers, Vue
props mutation, Python mutable defaults, bare except, global, and
type() ==.
Graceful degradation — if ast-grep (packaged as ast-grep or sg) is not
installed, fall back to the per-pattern flow: read REFERENCE.md,
which links each rule to its source .yml, and run the individual
ast-grep -p '<pattern>' --lang <lang> commands by hand. The rule project is the
fast path; the reference is the fallback.
Step 2: Judgment (the agent's actual work)
The scan is mechanical and reproducible; triage, recommendation, and fix
planning are the judgment work — do them yourself on the scan output rather than
spawning agents to re-run patterns:
- Severity triage — promote/demote each finding using the context in the
Category tables below and the app type (frontend/backend/CLI/library).
- Error-swallowing findings (empty catch, floating promises, bare except) →
delegate to
/code:hidden-failures --track errors for its severity model,
surfacing recommendations, and privacy redaction. Do not re-classify them here.
- Recommendations & fix planning — group systemic issues, note which findings
ast-grep can auto-
fix, and recommend process changes (lint rules, pre-commit).
Reserve any parallel Task fan-out for genuinely independent reasoning (e.g.
a deep security review or a framework-specific architecture pass) — never for
running the patterns, which Step 1 already did once, deterministically.
Analysis Categories
Based on the detected languages, analyze for these categories:
JavaScript/TypeScript Anti-patterns
- Callbacks, magic values, console.logs
- var usage, deprecated patterns
- Error swallowing (empty catch, floating promises) → delegate to
/code:hidden-failures --track errors
Async/Promise Patterns
- Nested callbacks, Promise constructor anti-pattern
- Error-handling coverage (unhandled/floating promises) → delegate to
/code:hidden-failures --track errors
Framework-Specific (if detected)
- Vue 3: Props mutation, reactivity issues, Options vs Composition API mixing
- React: Missing deps in hooks, inline functions, prop drilling
TypeScript Quality (if .ts files present)
- Excessive
any types, non-null assertions, type safety issues
Code Complexity
- Long functions (>50 lines), deep nesting (>4 levels), large parameter lists
Security Concerns
- eval usage, innerHTML XSS, hardcoded secrets, injection risks
Memory & Performance
- Event listeners without cleanup, setInterval leaks, inefficient patterns
Python Anti-patterns (if detected)
- Mutable default arguments, global variables
- Bare except and suppression patterns → delegate to
/code:hidden-failures --track errors
Delegated Category: Error Swallowing
Do NOT re-implement empty-catch / bare-except / floating-promise detection
here. Invoke /code:hidden-failures --track errors via the SlashCommand tool with the
same PATH and severity filter, then fold its findings into the
consolidated report under a dedicated Error Swallowing section.
Rationale: a single source of truth prevents drift between severity
models, app-context surfacing recommendations, and privacy redaction
policies. See code-quality-plugin/skills/code-hidden-failures/SKILL.md.
What the rule project does not cover (agent judgment)
Two catalog concerns are not structural single-node matches and stay as
agent-judgment passes on the code, not rules:
- Deep nesting / long functions / cyclomatic complexity — a metric over a
function body, not a pattern. Use
/code:complexity or read the flagged files.
- Floating promises — the repo's own toolchain is authoritative; defer to
tsc + the no-floating-promises ESLint rule, or /code:hidden-failures --track errors, rather than a broad structural rule that would flag every call.
Output Format
Consolidate findings into this structure:
## Anti-pattern Analysis Report
### Summary
- Total issues: X
- Critical: X | High: X | Medium: X | Low: X
- Categories with most issues: [list]
### Critical Issues (Fix Immediately)
| File | Line | Issue | Category |
|------|------|-------|----------|
| ... | ... | ... | ... |
### High Priority Issues
| File | Line | Issue | Category |
|------|------|-------|----------|
| ... | ... | ... | ... |
### Medium Priority Issues
[Similar table]
### Low Priority / Style Issues
[Similar table or summary count]
### Recommendations
1. [Prioritized fix recommendations]
2. [...]
### Category Breakdown
- **Security**: X issues (details)
- **Async/Promises**: X issues (details)
- **Code Complexity**: X issues (details)
- [...]
Optional Flags
--focus <category>: Focus on specific category (security, async, complexity, framework)
--severity <level>: Minimum severity to report (critical, high, medium, low)
--fix: Attempt automated fixes where safe
Post-Analysis
After consolidating findings:
- Prioritize issues by impact and effort
- Suggest which issues can be auto-fixed with ast-grep
- Identify patterns that indicate systemic problems
- Recommend process improvements (linting rules, pre-commit hooks)
See Also
- Rule project:
rules/ — the executable ast-grep catalog (sgconfig.yml + rules/lib/*.yml + rules/tests/*-test.yml); run ast-grep test -c rules/sgconfig.yml --skip-snapshot-tests to verify every rule against its fixtures
- Reference: REFERENCE.md - narrative catalog linking each pattern to its rule file
- Skill:
ast-grep-search - ast-grep usage reference
- Command:
/code:review - Comprehensive code review
- Agent:
security-audit - Deep security analysis
- Agent:
code-refactoring - Automated refactoring
Related Configure Skills
- If linting not configured →
/configure:linting for automated enforcement
- If security scanning not set up →
/configure:security for CI integration
1---
2created: 2025-12-16
3modified: 2026-07-06
4reviewed: 2026-07-06
5description: Analyze a codebase for anti-patterns using ast-grep. Use when finding magic numbers, console.logs, var usage, excessive any, eval/innerHTML security issues, or deep nesting.
6allowed-tools: Read, Bash(ast-grep *), Bash(sg *), Bash(rg *), Glob, Grep, TodoWrite, Task, SlashCommand
7args: "[PATH] [--focus <category>] [--severity <level>]"
8argument-hint: "[PATH] [--focus <category>] [--severity <level>]"
9name: code-antipatterns
10---
11
12## When to Use This Skill
13
14| Use this skill when... | Use something else instead when... |
15|------------------------|------------------------------------|
16| Running a parallel anti-pattern scan and producing a report | Looking up the full YAML rule catalog → see [REFERENCE.md](REFERENCE.md) |
17| Specifically targeting empty catches, floating promises, or `\|\| true` | Use the dedicated scanner → `code-hidden-failures --track errors` |
18| Finding success-on-empty / silent degradation patterns | Use the dedicated scanner → `code-hidden-failures --track degradation` |
19| Broad code-quality review across security, perf, and architecture | Run the full review delegate → `code-review` |
20
21## Context
22
23- Analysis path: `$1` (defaults to current directory if not specified)
24- JS/TS files: !`find . -type f \( -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" \)`
25- Vue files: !`find . -name "*.vue"`
26- Python files: !`find . -name "*.py"`
27
28## Your Task
29
30Perform comprehensive anti-pattern analysis. The **mechanical detection** is one
31deterministic `ast-grep scan` over a shipped rule project — you do **not** re-type
32`sg -p '…'` patterns and do **not** fan out agents just to run them. Your job is
33the **judgment**: severity triage, recommendations, and fix planning on top of the
34scan's structured findings.
35
36### Step 1: Run the deterministic scan
37
38The detection catalog lives as an ast-grep **rule project** in
39[`rules/`](rules/) (one `*.yml` per pattern under `rules/lib/`, each with a
40valid/invalid test fixture in `rules/tests/`). Run the whole catalog in one pass:
41
42```bash
43ast-grep scan -c ${CLAUDE_SKILL_DIR}/rules/sgconfig.yml --json=compact <path>
44```
45
46Each JSON finding carries `ruleId`, `file`, `range` (line/column), `message`, and
47the matched `text`. Parse this — it is the raw finding set for every category
48below. The rules cover: empty catch, `console.log`, `var`, `eval`/`new Function`,
49`innerHTML`/`outerHTML`, `as any` / `: any` annotations, magic-number timers, Vue
50props mutation, Python mutable defaults, bare `except`, `global`, and
51`type() ==`.
52
53**Graceful degradation** — if `ast-grep` (packaged as `ast-grep` or `sg`) is not
54installed, fall back to the per-pattern flow: read [REFERENCE.md](REFERENCE.md),
55which links each rule to its source `.yml`, and run the individual
56`ast-grep -p '<pattern>' --lang <lang>` commands by hand. The rule project is the
57fast path; the reference is the fallback.
58
59### Step 2: Judgment (the agent's actual work)
60
61The scan is mechanical and reproducible; **triage, recommendation, and fix
62planning are the judgment work** — do them yourself on the scan output rather than
63spawning agents to re-run patterns:
64
65- **Severity triage** — promote/demote each finding using the context in the
66 Category tables below and the app type (frontend/backend/CLI/library).
67- **Error-swallowing findings** (empty catch, floating promises, bare except) →
68 **delegate** to `/code:hidden-failures --track errors` for its severity model,
69 surfacing recommendations, and privacy redaction. Do not re-classify them here.
70- **Recommendations & fix planning** — group systemic issues, note which findings
71 ast-grep can auto-`fix`, and recommend process changes (lint rules, pre-commit).
72
73Reserve any parallel `Task` fan-out for **genuinely independent reasoning** (e.g.
74a deep security review or a framework-specific architecture pass) — never for
75running the patterns, which Step 1 already did once, deterministically.
76
77### Analysis Categories
78
79Based on the detected languages, analyze for these categories:
80
811. **JavaScript/TypeScript Anti-patterns**
82 - Callbacks, magic values, console.logs
83 - var usage, deprecated patterns
84 - Error swallowing (empty catch, floating promises) → **delegate** to `/code:hidden-failures --track errors`
85
862. **Async/Promise Patterns**
87 - Nested callbacks, Promise constructor anti-pattern
88 - Error-handling coverage (unhandled/floating promises) → **delegate** to `/code:hidden-failures --track errors`
89
903. **Framework-Specific** (if detected)
91 - **Vue 3**: Props mutation, reactivity issues, Options vs Composition API mixing
92 - **React**: Missing deps in hooks, inline functions, prop drilling
93
944. **TypeScript Quality** (if .ts files present)
95 - Excessive `any` types, non-null assertions, type safety issues
96
975. **Code Complexity**
98 - Long functions (>50 lines), deep nesting (>4 levels), large parameter lists
99
1006. **Security Concerns**
101 - eval usage, innerHTML XSS, hardcoded secrets, injection risks
102
1037. **Memory & Performance**
104 - Event listeners without cleanup, setInterval leaks, inefficient patterns
105
1068. **Python Anti-patterns** (if detected)
107 - Mutable default arguments, global variables
108 - Bare except and suppression patterns → **delegate** to `/code:hidden-failures --track errors`
109
110### Delegated Category: Error Swallowing
111
112Do NOT re-implement empty-catch / bare-except / floating-promise detection
113here. Invoke `/code:hidden-failures --track errors` via the SlashCommand tool with the
114same `PATH` and severity filter, then fold its findings into the
115consolidated report under a dedicated **Error Swallowing** section.
116
117Rationale: a single source of truth prevents drift between severity
118models, app-context surfacing recommendations, and privacy redaction
119policies. See `code-quality-plugin/skills/code-hidden-failures/SKILL.md`.
120
121### What the rule project does *not* cover (agent judgment)
122
123Two catalog concerns are not structural single-node matches and stay as
124**agent-judgment** passes on the code, not rules:
125
126- **Deep nesting / long functions / cyclomatic complexity** — a metric over a
127 function body, not a pattern. Use `/code:complexity` or read the flagged files.
128- **Floating promises** — the repo's own toolchain is authoritative; defer to
129 `tsc` + the `no-floating-promises` ESLint rule, or `/code:hidden-failures
130 --track errors`, rather than a broad structural rule that would flag every call.
131
132### Output Format
133
134Consolidate findings into this structure:
135
136```markdown
137## Anti-pattern Analysis Report
138
139### Summary
140- Total issues: X
141- Critical: X | High: X | Medium: X | Low: X
142- Categories with most issues: [list]
143
144### Critical Issues (Fix Immediately)
145| File | Line | Issue | Category |
146|------|------|-------|----------|
147| ... | ... | ... | ... |
148
149### High Priority Issues
150| File | Line | Issue | Category |
151|------|------|-------|----------|
152| ... | ... | ... | ... |
153
154### Medium Priority Issues
155[Similar table]
156
157### Low Priority / Style Issues
158[Similar table or summary count]
159
160### Recommendations
1611. [Prioritized fix recommendations]
1622. [...]
163
164### Category Breakdown
165- **Security**: X issues (details)
166- **Async/Promises**: X issues (details)
167- **Code Complexity**: X issues (details)
168- [...]
169```
170
171### Optional Flags
172
173- `--focus <category>`: Focus on specific category (security, async, complexity, framework)
174- `--severity <level>`: Minimum severity to report (critical, high, medium, low)
175- `--fix`: Attempt automated fixes where safe
176
177### Post-Analysis
178
179After consolidating findings:
1801. Prioritize issues by impact and effort
1812. Suggest which issues can be auto-fixed with ast-grep
1823. Identify patterns that indicate systemic problems
1834. Recommend process improvements (linting rules, pre-commit hooks)
184
185## See Also
186
187- **Rule project**: [`rules/`](rules/) — the executable ast-grep catalog (`sgconfig.yml` + `rules/lib/*.yml` + `rules/tests/*-test.yml`); run `ast-grep test -c rules/sgconfig.yml --skip-snapshot-tests` to verify every rule against its fixtures
188- **Reference**: [REFERENCE.md](REFERENCE.md) - narrative catalog linking each pattern to its rule file
189- **Skill**: `ast-grep-search` - ast-grep usage reference
190- **Command**: `/code:review` - Comprehensive code review
191- **Agent**: `security-audit` - Deep security analysis
192- **Agent**: `code-refactoring` - Automated refactoring
193
194## Related Configure Skills
195
196- If linting not configured → `/configure:linting` for automated enforcement
197- If security scanning not set up → `/configure:security` for CI integration