Real-world test on a 321-file TS/Svelte monorepo flagged 454 magic-number findings, ~82% of them noise: literals already assigned to a named const/field and numbers merely buried under a binary expression (e.g. a call arg inside a string concat). Tighten all 5 languages to: (1) require the literal be a DIRECT operand of a binary/comparison expression, and (2) exclude initializers of a named binding (const/var/let/field). Cuts magic-number ~67% with no loss on fixtures (each language still detects its genuine `x > 5000` case). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42 lines
1.0 KiB
YAML
42 lines
1.0 KiB
YAML
# Python — complexity smells (detection only, no `fix:` → Track B / semantic).
|
|
|
|
id: py-deep-nesting
|
|
language: Python
|
|
severity: warning
|
|
message: "Deeply nested conditional (>=3 levels) — consider guard clauses / early returns."
|
|
rule:
|
|
kind: if_statement
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
|
|
---
|
|
id: py-long-param-list
|
|
language: Python
|
|
severity: warning
|
|
message: "Long parameter list (>=5) — consider a dataclass / parameter object."
|
|
rule:
|
|
kind: parameters
|
|
has:
|
|
any:
|
|
- kind: identifier
|
|
- kind: typed_parameter
|
|
- kind: default_parameter
|
|
nthChild: 5
|
|
|
|
---
|
|
id: py-magic-number
|
|
language: Python
|
|
severity: info
|
|
message: "Magic number in an expression — consider a named constant."
|
|
rule:
|
|
all:
|
|
- kind: integer
|
|
- not: { regex: "^(0|1|2|10|100|1000)$" }
|
|
- inside: { any: [{ kind: binary_operator }, { kind: comparison_operator }] }
|
|
# Skip literals already named via assignment (e.g. `RETRIES = 5`).
|
|
- not: { inside: { kind: assignment, stopBy: end } }
|