eslint-plugin-math

raw JSON →
0.13.1 verified Sat Apr 25 auth: no javascript

ESLint plugin for Math object and Number linting. Current version 0.13.1, peer dependency ESLint >=8.57.0, requires Node ^18 or >=20. Provides ~30 rules including prefer-math-trunc, prefer-math-pow, prefer-number-is-finite. Supports flat config (eslint.config.js) and legacy .eslintrc. Offers a recommended config and fixable suggestions. Built on eslint-type-tracer for efficient type detection. Designed to catch common Math/Number anti-patterns and promote modern alternatives. Notable for its focus on correctness (e.g., prefer-math-sum-precise for floating point).

error Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/eslint-plugin-math/dist/index.js from /project/eslint.config.js not supported.
cause Plugin is ESM-only and cannot be required via CommonJS.
fix
Use import eslintPluginMath from 'eslint-plugin-math' in an ESM context or use dynamic import.
error ESLint couldn't find the plugin "eslint-plugin-math". (Note: plugins are not resolved relative to the config file.)
cause Plugin not installed or not in node_modules, or ESLint cannot resolve it.
fix
Run npm install --save-dev eslint-plugin-math eslint and ensure config references the plugin correctly.
error Configuration for rule "math/prefer-math-trunc" is invalid: Value "off" is the only valid severity for deprecated rules.
cause Rule 'math/prefer-math-trunc' might be deprecated in future version.
fix
Check rule docs and use 'error' or 'warn' if still supported; or use 'off' to disable.
breaking Plugin no longer supports ESLint <8.57.0 as of v0.10.0.
fix Upgrade ESLint to >=8.57.0 or pin plugin to <0.10.0.
breaking Plugin no longer supports Node <18 as of v0.10.0.
fix Upgrade Node to ^18 or >=20 or pin plugin to <0.10.0.
breaking Legacy config 'plugin:math/recommended' renamed to 'plugin:math/recommended-legacy' in v0.10.0.
fix Use 'plugin:math/recommended-legacy' in .eslintrc files. Flat config users should use eslintPluginMath.configs.recommended.
gotcha Flat config import must be default import; named exports 'configs' and 'rules' are also available but require destructuring.
fix Use `import eslintPluginMath from 'eslint-plugin-math'` or `import { configs } from 'eslint-plugin-math'`.
deprecated Option `reportBitwise` in rule 'prefer-math-trunc' was deprecated in v0.9.0.
fix Remove the option; behavior is now default.
npm install eslint-plugin-math
yarn add eslint-plugin-math
pnpm add eslint-plugin-math

Shows how to use the plugin with flat config, including recommended config and custom rules.

import eslintPluginMath from 'eslint-plugin-math';

export default [
  eslintPluginMath.configs.recommended,
  {
    rules: {
      'math/prefer-math-trunc': 'error',
      'math/no-static-infinity-calculations': 'warn',
    },
  },
];