Unnamed number
This is how the comment reads inline, under the flagged line.
Why it matters
86400000 or 3500 means nothing at the call site. When it changes, someone has to find every copy.
What to do
Name it with its unit: const DAY_MS = 86_400_000.
Examples
setTimeout(retry, 3500);
const RETRY_DELAY_MS = 3_500; setTimeout(retry, RETRY_DELAY_MS);
What it catches
It reads the shape of the code: functions, blocks, loops and calls. Languages: TypeScript and JavaScript, Python, Go, Rust, Java, C and similar. Scope: Shipped code only. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
setTimeout(retry, 3500);
Left alone
const RETRY_MS = 3500; setTimeout(retry, RETRY_MS);
res.status(404);
const o = {
compactionThreshold: 200_000,
};Research
Unnamed numbers in logic. Readers cannot tell what the number means or which unit it uses.
- ESLint: no-magic-numbers
- Ruff rules
- skill: code-review
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"magic-number"
],
"severity": {
"magic-number": "medium"
}
}
}
3500is a bare number. Name it, with its unit, so the next reader knows what it means.