eslint/rules/numbers
Numbers and dates: Arithmetic, precision, magic numbers, bitwise operators and dates. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
22 rules, 13 on. Source: lint/eslint/rules/numbers.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-loss-of-precision | error | JS + TS | Disallow literal numbers that lose precision | — |
use-isnan | error | JS + TS | Require calls to isNaN() when checking for NaN | — |
no-bitwise | off | JS + TS | Disallow bitwise operators | Off: colour parsing and formatting need bitwise math. |
no-magic-numbers | off | JS + TS | Disallow magic numbers | Replaced by the TS version. |
no-octal | error | JS + TS | Disallow octal literals | — |
no-plusplus | warn, {"allowForLoopAfterthoughts":true} | JS + TS | Disallow the unary operators ++ and -- | i++ only in for loops, += 1 elsewhere. |
prefer-exponentiation-operator | error | JS + TS | Disallow the use of Math.pow in favor of the ** operator | — |
prefer-numeric-literals | error | JS + TS | Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals | — |
radix | info | JS + TS | Enforce the use of the radix argument when using parseInt() | — |
sonarjs/no-nested-incdec | off | JS + TS | Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression | Off: not in the Sonar way profile of SonarQube. |
sonarjs/non-number-in-arithmetic-expression | off | JS + TS | Arithmetic operators should only have numbers as operands | Off: not in the Sonar way profile of SonarQube. |
sonarjs/operation-returning-nan | off | JS + TS | Arithmetic operations should not result in "NaN" | Off: not in the Sonar way profile of SonarQube. |
sonarjs/values-not-convertible-to-numbers | off | JS + TS | Values not convertible to numbers should not be used in numeric comparisons | Off: not in the Sonar way profile of SonarQube. |
sonarjs/updated-const-var | off | JS + TS | "const" variables should not be reassigned | Off: duplicate of no-const-assign. |
sonarjs/bitwise-operators | error | JS + TS | Bitwise operators should not be used in boolean contexts | — |
sonarjs/no-useless-increment | error | JS + TS | Values should not be uselessly incremented | — |
sonarjs/non-existent-operator | error | JS + TS | Non-existent operators '=+', '=-' and '=!' should not be used | — |
no-octal | off | TS | Disallow octal literals | — |
@typescript-eslint/no-loss-of-precision | off | TS | Disallow literal numbers that lose precision | Deprecated: the core rule supports TypeScript. |
@typescript-eslint/no-magic-numbers | warn, {"ignore":[-1,0,1,2],"ignoreDefaultValues":true,"ignoreEn… | TS | Disallow magic numbers | Custom: named constants for every number but the obvious ones (specs and benchmarks excepted, see below). Warn: a documented literal can read better than a constant. |
@typescript-eslint/no-unsafe-unary-minus | error | TS | Require unary negation to take a number | — |
@typescript-eslint/restrict-plus-operands | error | TS | Require both operands of addition to be the same type and be bigint, number, or string | — |