-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
new lint: source_item_ordering
#13376
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
a1e3223
to
173dd5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The big open question is around macro-generated code. Otherwise, apart from a few small doc improvements, this looks good.
/// implemented in the code. Sometimes this will be referred to as | ||
/// "bike-shedding". | ||
/// | ||
/// Keep in mind, that ordering source code alphabetically can lead to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be under a # Known problems
header.
We also might want to add that the lint doesn't supply suggestions because it's quite hard to produce them in a correct way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it down to the (now renamed) chapter "Known Problems". Is there a standard way to write this?
Ctrl+F "# Known" yields different ways to write this: "Known problems", "Known Problems", "Known issues"
const B: i8 = 1; | ||
|
||
const A: i8 = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see some macro-generated items. I'm open to debate whether the lint should apply to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the uitests to contain some derive macros. What other things should be tested?
I also added a uitest that passes the ordering lint and produces no output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that I've added ordering for trait impls on the module level.
I will add at least a test where I reconfigure item placement of trait impls into its own section, such that it's certainly possible to split trait defs and trait impls. The default groups all CamelCase items, including impls, but I can see why somebody would like to split this category up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I've added a bunch of test cases, including modified configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that it can't reasonably be applied to macro-generated items, there's a ton of things in a real codebase that generates items. Using the in_external_macro()
function from clippy_utils to filter items yields a decent behaviour in a real code-base.
Also, turns out we do adhere surprisingly well to our own convention, even though we do so manually. Some typos and forgotten things, but nothing majorly wrong in our source file ordering. :-)
I believe this is now in a reviewable state and should work as advertised.
@rustbot author |
☔ The latest upstream changes (presumably #13322) made this pull request unmergeable. Please resolve the merge conflicts. |
3953233
to
b46da06
Compare
I'd like to discuss whether or not I should implement another loop before generating lint output that determines the actual location where a snippet should be placed. |
1aa0157
to
8af8a22
Compare
☔ The latest upstream changes (presumably #13334) made this pull request unmergeable. Please resolve the merge conflicts. |
8af8a22
to
72fccdf
Compare
☔ The latest upstream changes (presumably #13395) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry you had to wait so long, but personal matters left me little time to review this rather large change. I'd like to check if the |
1239c30
to
1731ac9
Compare
/// | ||
/// [cargo-pgo]: https://github.com/Kobzol/cargo-pgo/blob/main/README.md | ||
/// | ||
#[clippy::version = "1.81.0"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[clippy::version = "1.81.0"] | |
#[clippy::version = "1.82.0"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
1731ac9
to
97a3b24
Compare
97a3b24
to
f7ab2c9
Compare
changelog: [
source_item_ordering
]: Introduced a new restriction lint that checks the ordering of items in Modules, Enums, Structs, Impls and Traits.From the written documentation:
I tried to build it as configurable as possible, as such a highly opinionated lint should be adjustable to personal opinions.
I'm open to any input and will be available both here and on the zulip for communication. In the meantime I'll be testing this lint against my own code-bases, which I've (manually) kept ordered with the default config, to see how well it works in practice.
And lastly, a big thanks to the community for making clippy the best linter there is!