Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BD103 opened this issue Jun 29, 2024 · 2 comments
Closed

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

BD103 opened this issue Jun 29, 2024 · 2 comments
Labels
A-lint Area: New lints

Comments

@BD103
Copy link
Contributor

BD103 commented Jun 29, 2024

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.

@BD103 BD103 added the A-lint Area: New lints label Jun 29, 2024
@Alexendoo
Copy link
Member

Looks like there's a pending effort to get this into rustfmt - rust-lang/rustfmt#5834

@BD103
Copy link
Contributor Author

BD103 commented Jun 30, 2024

Awesome, I didn't see that in my initial search. Thanks for pointing it out!

@BD103 BD103 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants