no-magic-numbers
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-magic-numbers": "error",
},
},
];const dutyFreePrice = 100,
finalPrice = dutyFreePrice + (dutyFreePrice * 0.25);const data = ['foo', 'bar', 'baz'];
const dataLast = data[2];let SECONDS;
SECONDS = 60;const TAX = 0.25;
const dutyFreePrice = 100,
finalPrice = dutyFreePrice + (dutyFreePrice * TAX);Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
no-magic-numbers
eslint
export default [
{
rules: {
"no-magic-numbers": "error",
},
},
];no-magic-numbers
eslint plugin · style
{
"rules": {
"no-magic-numbers": "error"
}
}style/noMagicNumbers
style · since 2.1.0
{
"linter": {
"rules": {
"style": {
"noMagicNumbers": "error"
}
}
}
}Enforce a maximum number of statements allowed in function blocks
Enforce a maximum number of lines of code in a function
Require or disallow initialization in variable declarations
Disallow assignments that can lead to race conditions due to usage of await or yield