oxc icon indicating copy to clipboard operation
oxc copied to clipboard

`unicorn/no-zero-fractions` suggests subpar fixes

Open rzvxa opened this issue 6 months ago • 0 comments

This rule fails 3 kinds of fixer tests. We should either stop suggesting them or correct their behavior.

  1. Spacing(Invalid code) For:
function foo(){return.0}

We generate:

function foo(){return0}

Where it should be:

function foo(){return 0}
  1. Parenthesized expressions(dangerous):

For:

1.00.toFixed(2)

We generate:

1.toFixed(2)

Where it should be:

(1).toFixed(2)
  1. Exponential numbers(Inconvenient):

For:

const foo = 1.e10

We generate:

const foo = 110

Where it should be:

const foo = 1e10

Tests are introduced in #4783

https://github.com/oxc-project/oxc/blob/4dd29dbc2beac49df28ccf15ea433ffbaf3e9fd4/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs#L149-L164

rzvxa avatar Aug 09 '24 13:08 rzvxa