Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint-plugin-big-number-rules #343

Open
shuckster opened this issue Apr 9, 2023 · 0 comments
Open

eslint-plugin-big-number-rules #343

shuckster opened this issue Apr 9, 2023 · 0 comments

Comments

@shuckster
Copy link

I made an eslint plugin some time ago that's reached v2 and I thought it was now useful enough to share more broadly.

Essentially it offers replacements like:

from to plugin will also suggest
0.1 + 0.2 BigNumber.sum(0.1, 0.2) ('').concat(0.1, 0.2) and `${0.1}${0.2}` when you want string-concatenation instead of FP arithmetic
result === 0.3 BigNumber(result).isEqualTo(0.3) Object.is(result, 0.3) when you want to strictly compare things that are not FP calculations
19.99 * 0.1 BigNumber(19.99).multipliedBy(0.1)
1 < 2 BigNumber(1).isLessThan(2)
2 >>> 4 BigNumber(2).shiftedBy(4)
4 << 2 BigNumber(4).shiftedBy(-2)
Math.min(1, 2) BigNumber.minimum(1, 2)
Math.sign(-6) BigNumber(-6).comparedTo(0)
(1).toFixed(2) BigNumber(1).toFixed(2)
parseFloat('1.2') BigNumber('1.2')
Number.parseFloat('2.1') BigNumber('2.1')

There's configuration to enforce the rules only in files that import 'bignumber.js', along with other ways and means to mitigate the number of warnings if you introduce the plugin into a large code-base.

It's proved useful to me and I hope for others too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant