Skip to content

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.

RuleSettingFilesWhat it checksWhy
no-loss-of-precisionerrorJS + TSDisallow literal numbers that lose precision—
use-isnanerrorJS + TSRequire calls to isNaN() when checking for NaN—
no-bitwiseoffJS + TSDisallow bitwise operatorsOff: colour parsing and formatting need bitwise math.
no-magic-numbersoffJS + TSDisallow magic numbersReplaced by the TS version.
no-octalerrorJS + TSDisallow octal literals—
no-pluspluswarn, {"allowForLoopAfterthoughts":true}JS + TSDisallow the unary operators ++ and --i++ only in for loops, += 1 elsewhere.
prefer-exponentiation-operatorerrorJS + TSDisallow the use of Math.pow in favor of the ** operator—
prefer-numeric-literalserrorJS + TSDisallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals—
radixinfoJS + TSEnforce the use of the radix argument when using parseInt()—
sonarjs/no-nested-incdecoffJS + TSIncrement (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expressionOff: not in the Sonar way profile of SonarQube.
sonarjs/non-number-in-arithmetic-expressionoffJS + TSArithmetic operators should only have numbers as operandsOff: not in the Sonar way profile of SonarQube.
sonarjs/operation-returning-nanoffJS + TSArithmetic operations should not result in "NaN"Off: not in the Sonar way profile of SonarQube.
sonarjs/values-not-convertible-to-numbersoffJS + TSValues not convertible to numbers should not be used in numeric comparisonsOff: not in the Sonar way profile of SonarQube.
sonarjs/updated-const-varoffJS + TS"const" variables should not be reassignedOff: duplicate of no-const-assign.
sonarjs/bitwise-operatorserrorJS + TSBitwise operators should not be used in boolean contexts—
sonarjs/no-useless-incrementerrorJS + TSValues should not be uselessly incremented—
sonarjs/non-existent-operatorerrorJS + TSNon-existent operators '=+', '=-' and '=!' should not be used—
no-octaloffTSDisallow octal literals—
@typescript-eslint/no-loss-of-precisionoffTSDisallow literal numbers that lose precisionDeprecated: the core rule supports TypeScript.
@typescript-eslint/no-magic-numberswarn, {"ignore":[-1,0,1,2],"ignoreDefaultValues":true,"ignoreEn…TSDisallow magic numbersCustom: 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-minuserrorTSRequire unary negation to take a number—
@typescript-eslint/restrict-plus-operandserrorTSRequire both operands of addition to be the same type and be bigint, number, or string—

Generated from the JSDoc of the sources.