src/content/docs/linter/rules/no-magic-numbers.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v2.1.0` - Diagnostic Category: [`lint/style/noMagicNumbers`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/no-magic-numbers`](https://typescript-eslint.io/rules/no-magic-numbers){
"linter": {
"rules": {
"style": {
"noMagicNumbers": "error"
}
}
}
}
Reports usage of "magic numbers" — numbers used directly instead of being assigned to named constants.
Its goal is to improve code maintainability and readability by encouraging developers to extract such numbers into named constants, making their purpose explicit.
It ignores:
JSON.stringify(22), parseInt("123", 8))a & 7, a | 7)<div>{1}</div>){ tax: 0.25 })let total = price * 1.23; // Magic number for tax rate
const TAX_RATE = 1.23;
let total = price * TAX_RATE;
const TAX_RATE = 1.23 as const;
let total = price * TAX_RATE;