Skip to content

Decimal literal suffix of 0 (2. vs. 2.0) #13022

@BD103

Description

@BD103

What it does

This lint checks if a floating-point number with no decimals explicitly writes .0 or just .

In the Bevy game engine there are a lot of examples that use floating-point numbers. Because so many people contribute to these examples, there's a large mix between literals like 1.0 and 1.. Here's the most egregious example. Having a lint that picks one form and denies the other would be great for consistency, though it should probably be within the pedantic or nursery groups.

I'm not sure how a user would choose which form they prefer, though, since exclusive lints are probably not a good idea.

Advantage

  • Increases consistency of writing floating point numbers by only allowing one form.

Drawbacks

  • It might be difficult to implement, because there's no necessarily "correct" form. Both have their own benefits, meaning you would have to let the user decide.

Example

let x = 1.0;

Could be written as:

let x = 1.;

And vice-versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions