Skip to content

noZeroFractions (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noZeroFractions": "error"
}
}
}
}

Disallow number literals with zero fractions or dangling dots.

There is no difference in JavaScript between, for example, 1, 1.0, and 1.. This rule suggests the shorter form for consistency and brevity.

const foo = 1.0;
code-block.js:1:13 lint/nursery/noZeroFractions  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This number literal has a zero fraction.

> 1 │ const foo = 1.0;
│ ^^^
2 │

ℹ The fractional part is redundant. It has the same runtime value and makes the literal longer than it needs to be.

ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9829 for more information or to report possible bugs.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Remove the redundant zero fraction.

1 │ - const·foo·=·1.0;
1 │ + const·foo·=·1;
2 2 │

const foo = 1.;
code-block.js:1:13 lint/nursery/noZeroFractions  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This number literal has a dangling dot.

> 1 │ const foo = 1.;
│ ^^
2 │

ℹ The fractional part is redundant. It has the same runtime value and makes the literal longer than it needs to be.

ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9829 for more information or to report possible bugs.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Remove the dangling dot.

1 │ const·foo·=·1.;
│ -
const foo = 123.00e20;
code-block.js:1:13 lint/nursery/noZeroFractions  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This number literal has a zero fraction.

> 1 │ const foo = 123.00e20;
│ ^^^^^^^^^
2 │

ℹ The fractional part is redundant. It has the same runtime value and makes the literal longer than it needs to be.

ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9829 for more information or to report possible bugs.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Remove the redundant zero fraction.

1 │ - const·foo·=·123.00e20;
1 │ + const·foo·=·123e20;
2 2 │

const foo = 1;
const bar = -1.1;
const baz = 123.456;
const qux = 1e3;