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>
39 lines
975 B
YAML
39 lines
975 B
YAML
# JavaScript/JSX — complexity smells (detection only, no `fix:` → Track B / semantic).
|
|
|
|
id: js-deep-nesting
|
|
language: JavaScript
|
|
severity: warning
|
|
message: "Deeply nested conditional (>=3 levels) — consider guard clauses / extract method."
|
|
rule:
|
|
kind: if_statement
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
|
|
---
|
|
id: js-long-param-list
|
|
language: JavaScript
|
|
severity: warning
|
|
message: "Long parameter list (>=5) — consider a parameter object."
|
|
rule:
|
|
kind: formal_parameters
|
|
has:
|
|
kind: identifier
|
|
nthChild: 5
|
|
|
|
---
|
|
id: js-magic-number
|
|
language: JavaScript
|
|
severity: info
|
|
message: "Magic number in an expression — consider a named constant."
|
|
rule:
|
|
all:
|
|
- kind: number
|
|
- not: { regex: "^(0|1|2|-1|10|100|1000)$" }
|
|
- inside: { kind: binary_expression }
|
|
- not: { inside: { kind: variable_declarator, stopBy: end } }
|
|
- not: { inside: { kind: field_definition, stopBy: end } }
|