Skip to content

VBC-015: magic-numbers

warning

Category: clean-code
Analysis: Regex (line by line)
File types: .js, .ts, .tsx, .py, .astro
Scope: source code only, ignoring anything inside strings and comments
Excluded paths: **/test/**, **/tests/**, **/__tests__/**, **/testdata/**, **/fixtures/**, **/test_*.py, **/*_test.py, **/test.py, **/conftest.py, **/*_test.go, **/*_bench.go, **/*.test.*, **/*.spec.*, **/bench/**, **/benchmark*, **/*corpus*, **/*payload*
Tags: clean-code

What it reports

Magic number '{match}' detected at line {line}. Consider using a named constant (e.g., SECONDS_IN_DAY).

Flagged

js
setTimeout(retry, 1000);
js
const expiry = now + 86400;

Not flagged

js
const ONE_SECOND_MS = 1000;
js
const port = 10001;

Pattern

regex
(?<!\w)(?<!(?:const|let|var|static|final)\s{1,4}[A-Za-z_$][\w$]{0,60}\s{0,4}=\s{0,4})(?:86400|3600|1000|60)(?![\w.])

Released under the MIT License.