← ClaudeAtlas

ast-anti-pattern-slayerlisted

Parses Python or JavaScript-style source into an AST, computes cyclomatic complexity v(G) as decision count plus one, maximum block nesting depth, bare except clauses and unreachable dead code, then uses a conservative ast.NodeTransformer to rewrite trailing if/else wrappers into semantics-preserving early return and continue guard clauses, emitting a structured JSON diagnostics report with file line and column locations.
RMAzrim/opencode-artes · ★ 2 · AI & Automation · score 76
Install: claude install-skill RMAzrim/opencode-artes
# AST Anti-Pattern Slayer ## 1. System Architecture & Prerequisites - Runtime binary: **Python 3.9 or newer** (requires `ast.unparse`, stable type hints, and `ast.TryStar`/`ast.Match` handling). Python 3.11+ is recommended. - Standard library used (no third-party packages): `ast`, `argparse`, `json`, `sys`, `pathlib`. - Input surface: a single Python source file (`*.py`) with the assignment to execute. - The module never executes the analyzed code; all analysis is static and import-free, so the input file does not need resolvable imports at analysis time. - The sample reference implementation `ast_slayer.py` doubles as a CLI: - `python ast_slayer.py path/to/script.py` — prints the JSON report. - `python ast_slayer.py path/to/script.py --fix` — additionally rewrites the file in place with guard clauses (only when a conservative rewrite is possible). - JavaScript-style input is supported only conceptually (the same decision-node counting maps onto Mozilla ESTree shapes once the AST is parsed with a JS toolchain such as `acorn`/`esprima`); this skill ships the Python AST pipeline, which is architecture-identical. ## 2. Input/Output Data Contracts ### 2.1 CLI input options (JSON Schema) ```json { "$schema": "http://json-schema.org/draft-07/schema#", "title": "ast_slayer_cli_options", "type": "object", "properties": { "path": { "type": "string", "description": "Path to the Python source file to analyze." }, "fix": { "type": "boolean", "defau