Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

unicorn/require-number-to-fixed-digits-argument

Require the digits argument of Number#toFixed()

Without an argument, toFixed() rounds to zero decimals, so (1.5).toFixed() is "2". A reader might expect two decimals, or the number unchanged. Writing the number of digits out removes the guesswork.

The rule only looks at the method name, so it reports .toFixed() without arguments on any object.

--fix adds 0, which keeps the result the same.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/require-number-to-fixed-digits-argument" = "error" # or "warn"

Examples

Reported:

const total = price.toFixed();

Not reported:

const total = price.toFixed(2);
const rounded = price.toFixed(0);