You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
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 arithmeticresult === 0.3
BigNumber(result).isEqualTo(0.3)
Object.is(result, 0.3)
when you want to strictly compare things that are not FP calculations19.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.
The text was updated successfully, but these errors were encountered: