rust-lang / rust-lang/rust-clippy
Enforce consistent way of referring to crate root
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
There are a few different ways by which to refer to the root of a crate:
cratesuper- Crate name
This lint enforces a consistent way of referring to the root of a crate.
I don't think there is much consensus in the community on any one of these styles being better than the other but it's nice for the one style to be adhered to throughout a crate. I figure this belongs in restriction.
Currently there are some overlapping lints in restriction eg. implicit_return/needless_return. The user selects a particular style by enabling one and disabling the other.
Perhaps it makes sense to do the same thing here and so this lint suggestion is really a suggestion for 3 new lints.
Advantage
Makes searching code easier. If I want to find all places where root of crate is referenced, I can find them easier.
Makes some kinds of refactoring easier. If I want to nest some existing modules inside a new module, it is marginally easier if there is a single kind of root reference to update.
Drawbacks
It might make you use a particular way of referring to crate root that isn't appropriate for the instance
If a crate has a particularly long name
use crate::submodule;
could become
use long_crate_name_that_is_painful_to_write_and_takes_time_to_say::submodule;
Example
Treating the different styles separately:
crate
use super::module_a;
use crate_name::module_b;
Could be written as:
use crate::module_a;
use crate::module_b;
super
use crate::module_a;
use crate_name::module_b;
Could be written as:
use super::module_a;
use super::module_b;
Crate name
use crate::module_a;
use super::module_b;
Could be written as:
use crate_name::module_a;
use crate_name::module_b;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue discussion and the existing restriction lints implicit_return and needless_return, which are cited as a possible model. Resolve whether this should be one lint or three and which crate-root style each should enforce; done requires an agreed design and corresponding implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100