src/content/docs/linter/rules/use-number-namespace.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.5.0` - Diagnostic Category: [`lint/style/useNumberNamespace`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/prefer-number-properties`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-number-properties.md){
"linter": {
"rules": {
"style": {
"useNumberNamespace": "error"
}
}
}
}
Use the Number properties instead of global ones.
ES2015 moved some globals into the Number properties for consistency.
The rule doesn't report the globals isFinite and isNaN because they have a slightly different behavior to their corresponding Number's properties Number.isFinite and Number.isNaN.
You can use the dedicated rules noGlobalIsFinite and noGlobalIsNan to enforce the use of Number.isFinite and Number.isNaN.
parseInt("1"); // true
parseFloat("1.1"); // true
NaN; // true
Infinity; // true
-Infinity; // true
Number.parseInt("1"); // false
Number.parseFloat("1.1"); // false
Number.NaN; // false
Number.POSITIVE_INFINITY; // false
Number.NEGATIVE_INFINITY; // false