Skip to content

math/prefer-number-max-safe-integer โ€‹

enforce the use of Number.MAX_SAFE_INTEGER instead of other ways

  • โš™๏ธ This rule is included in "plugin:math/recommended".
  • ๐Ÿ”ง The --fix option on the command line can automatically fix some of the problems reported by this rule.
  • ๐Ÿ’ก Some problems reported by this rule are manually fixable by editor suggestions.

๐Ÿ“– Rule Details โ€‹

This rule aims to enforce the use of Number.MAX_SAFE_INTEGER instead of other ways to represent the maximum safe integer value.

Number.MAX_SAFE_INTEGER provides several advantages over hardcoded values:

  • Clarity of intent: Immediately obvious that you're using the maximum safe integer
  • Precision: Guaranteed to be the exact maximum safe integer value (2โตยณ - 1)
  • Maintainability: Avoids potential typos in hexadecimal or decimal literals
  • Self-documenting: Makes the code intention clear without comments
Now loading...

๐Ÿ”ง Options โ€‹

Nothing.

๐Ÿ“š Further reading โ€‹

๐Ÿš€ Version โ€‹

This rule was introduced in eslint-plugin-math v0.3.0

๐Ÿ” Implementation โ€‹