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

Lint sparse_imports #44

Open
Veetaha opened this issue Jul 28, 2023 · 1 comment
Open

Lint sparse_imports #44

Veetaha opened this issue Jul 28, 2023 · 1 comment
Labels
A-user-story Area: A user story or a related issue

Comments

@Veetaha
Copy link

Veetaha commented Jul 28, 2023

Lint explanation

Detect use statements that are separated with empty lines, and suggest removing them. The reasoning is that imports that don't have empty lines between them are nicely sorted by rustfmt in an alphabetical order.

This does apply to use statements with different visibility.

This lint is rather subjective and should be opt-in.

Example code

Bad

use std::path::Path;

use serde::Deserialize;

Good

use serde::Deserialize;
use std::path::Path;

Notes

marker must have the ability to provide information about whitespace in code to lints to implement this. I know it is not obvious what AST nodes whitespace (just like comments) should be nested under, but this is not very important. Rust-analyzer, for example has a lossless AST, and it attaches the leading whitespace to AST nodes (more details in rust-marker/marker#189 (comment)).

@Veetaha Veetaha added the A-user-story Area: A user story or a related issue label Jul 28, 2023
@xFrednet
Copy link
Member

xFrednet commented Aug 1, 2023

It should be possible to extract the line location from the spans of the use items. That's how Clippy deals with similar lints. Though right now, spans are a bit broken 😅 rust-marker/marker#175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-user-story Area: A user story or a related issue
Projects
None yet
Development

No branches or pull requests

2 participants