Skip to content
← Back to rules

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

🛠️ An auto-fix is available for this rule.

What it does

Enforce using the digits argument with Number#toFixed().

Why is this bad?

It's better to make it clear what the value of the digits argument is when calling Number#toFixed(), instead of relying on the default value of 0.

Examples

Examples of incorrect code for this rule:

javascript
number.toFixed();

Examples of correct code for this rule:

javascript
number.toFixed(0);
number.toFixed(2);

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/require-number-to-fixed-digits-argument": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/require-number-to-fixed-digits-argument": "error",
  },
});
bash
oxlint --deny unicorn/require-number-to-fixed-digits-argument

References