src/content/docs/linter/rules/use-numeric-literals.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/useNumericLiterals`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`prefer-numeric-literals`](https://eslint.org/docs/latest/rules/prefer-numeric-literals){
"linter": {
"rules": {
"complexity": {
"useNumericLiterals": "error"
}
}
}
}
Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals
JavaScript provides literal forms for binary, octal, and hexadecimal numbers.
For example: 0b11, 0o77, and 0xff.
Using the literal forms enable static code analysis and avoid unnecessary computations.
parseInt("111110111", 2);
Number.parseInt("767", 8);
Number.parseInt("-1f7", 16);
parseInt(1);
parseInt(1, 3);
Number.parseInt(1);
Number.parseInt(1, 3);
0b111110111 === 503;
0o767 === 503;
0x1F7 === 503;
a[parseInt](1,2);
parseInt(foo);
parseInt(foo, 2);
Number.parseInt(foo);
Number.parseInt(foo, 2);