1.0.2 • Published 5 months ago
eslint-plugin-currency-operations v1.0.2
Eslint Plugin Currency Operations
This plugin aims to help to prevent floating point issues in javascript such as:
2.51 + .01; // => 2.5199999999999996
2.52 - .01; // => 2.5100000000000002
Instalation
With npm:
npm install --save-dev eslint-plugin-currency-operations
With yart:
yarn add -D eslint-plugin-currency-operations
Rules
no-manual-currency-math
It triggers a warning when floating point operations with "+", "-", "/", "*" operations are done.
// valid
const sum = 1 + 2;
// invalid
const total = 1 + 0.2;
Setup in your project
To setup in your project simply install as a dev dependency and then add it in the eslint
configuration file in the plugins
section and if desired adjust the rule severity in the rules
// eslint config
{
...,
"plugins": ["currency-operations"],
"rules": {
"currency-operations/no-manual-currency-math": "error"
}
}