@okidoo/eslint9-plugin-no-arithmetic
v1.0.0
Published
Forbid arithmetic and suggest float-safe alternatives.
Downloads
2
Readme
eslint-plugin-no-arithmetic
@Fork of eslint-plugin-no-arithmetic Fix metadata of the package because eslint 9 was throwing an error when using a custom message.
ESLint plugin containing a rule for detecting arithmetic in JavaScript source. Floating-point math can lead to imprecise results, so this plugin directs users to float-safe alternative helper methods.
Configuration
Add the following to your eslint
config:
import noArithmetic from "@okidoo/eslint9-plugin-no-arithmetic";
{
//...
plugins: {
// ...
"@okidoo/eslint9-plugin-no-arithmetic",
// ...
},
rules: {
"@okidoo/eslint9-plugin-no-arithmetic/no-arithmetic": "error",
// ...
}
}
Or with a custom alternative suggestion:
{
//...
plugins: [
// ...
"@okidoo/eslint9-plugin-no-arithmetic",
// ...
],
rules: {
"@okidoo/eslint9-plugin-no-arithmetic/no-arithmetic": [
"error",
{
message:
"Floating-point math can lead to imprecise results, use MathUtil",
},
],
// ...
}
}
Options
message
Sets the hint message.
type:
string
default:
"use float-safe alternatives"
ignoreIteratorLike
When enabled, does not error on operations that look like an increment / decrement. We define this as the right-hand value of a binary +
/ -
operation being the literal value 1
.
type: boolean
default:
true