Forbid arithmetic and suggest float-safe alternatives.
npm install @vertical-made/eslint-plugin-no-arithmeticESLint 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.
Add the following to your eslint config:
``js`
{
//...
plugins: [
// ...
"@vertical-made/no-arithmetic",
// ...
],
rules: {
"@vertical-made/no-arithmetic/no-arithmetic": "error",
// ...
}
}
Or with a custom alternative suggestion:
`jsfloatSafe*
{
//...
plugins: [
// ...
"@vertical-made/no-arithmetic",
// ...
],
rules: {
"@vertical-made/no-arithmetic/no-arithmetic": [
"error",
{ message: "use the helpers in myUtils.js" }`
// ...
}
}
Sets the hint message.
> type: string"use float-safe alternatives"
>
> default:
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`