Skip to content

unicorn/no-zero-fractions suggests subpar fixes #4788

@rzvxa

Description

@rzvxa

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

// maybe todo
// In the following tests, the comments did not pass the fixer.
// (r"const foo = 1.e10", r"const foo = 1e10"),
// (r"const foo = +1.e-10", r"const foo = +1e-10"),
// (r"const foo = -1.e+10", r"const foo = -1e+10"),
(r"const foo = (1.).toString()", r"const foo = (1).toString()"),
// (r"1.00.toFixed(2)", r"(1).toFixed(2)"),
// (r"1.00 .toFixed(2)", r"(1) .toFixed(2)"),
(r"(1.00).toFixed(2)", r"(1).toFixed(2)"),
// (r"1.00?.toFixed(2)", r"(1)?.toFixed(2)"),
(r"a = .0;", r"a = 0;"),
// (r"a = .0.toString()", r"a = (0).toString()"),
// (r"function foo(){return.0}", r"function foo(){return 0}"),
// (r"function foo(){return.0.toString()}", r"function foo(){return (0).toString()}"),
// (r"function foo(){return.0+.1}", r"function foo(){return 0+.1}"),

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linterArea - LinterC-bugCategory - Buggood first issueExperience Level - Good for newcomers

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions