-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
add lint for struct field names #11496
Conversation
r? @dswij (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #11511) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @y21 |
Failed to set assignee 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.
One question: would it make sense to allow is_*
fields? I imagine this would be a common case where people would want to allow the lint
Yes, I agree it would make sense to silence the lint in this case. I could add that prefix as an exception so that it does not trigger the lint, but I wasn't sure if adding particular cases was appropiate. I think even in the case in which
I don't have a strong preference for the second case. |
The idea of allowing |
654cea6
to
931cac8
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.
We should also have a test for the configuation option (in tests/ui-toml) to make sure it works and continues to work to avoid issues such as #11481
Also I wonder if we can merge this file with enum_variants since they do seem very related and share a bit of logic. There's also other lints as part of the same lint pass such as module_name_repetitions, for catching a shared {pre,post}fix between modules and structs or other items |
Yeah, they could be in the same file, although it might be good to change the name The module inception part already checks the struct names as well, so we could merge everything together with a more general name for the file (instead of |
I agree that the lint pass name |
0824c5d
to
04728ad
Compare
prevent ice when threshold is 0 and enum has no variants changelog: [`lint_name`]: prevent ice when threshold is 0 and enum has no variants r? `@y21` Fixes the same ice issue raised during review of #11496
prevent ice when threshold is 0 and enum has no variants changelog: [`enum_variant_names`]: prevent ice when threshold is 0 and enum has no variants r? `@y21` Fixes the same ice issue raised during review of #11496
☔ The latest upstream changes (presumably #11552) made this pull request unmergeable. Please resolve the merge conflicts. |
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 change from enum_variants to item_name_repetitions is great, I like that. It's probably worth including another changelog entry in the description that says that the enum_variant_name_threshold
config option was renamed to item_name_threshold
.
It also looks like the error in CI happens because it's testing that each directory in tests/ui-toml
has an associated test, but tests/ui-toml/item_name_repetitions
doesn't have any direct test files, only directories. Might have to flatten this to item_name_repetitions_threshold_0
and item_name_repetitions_threshold_5
🤔
}; | ||
let mut post = pre.clone(); | ||
post.reverse(); | ||
for field in fields.iter().skip(1) { |
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 rest of this function from here on should be basically nearly equivalent to what's in check_variants
once the other PR gets merged, in terms of what it does to the two Vec<&str>
s, right? Just emits a different lint in the end.
Depending on if that PR gets merged soon we could perhaps move some of this to its own function so that the other lint gets to reuse the logic and we wouldn't need to duplicate stuff here
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.
yeah I agree, I can wait for the bugfix to be merged and refactor this part.
I think it was failing because I had one stderr file with the old name that did not have any associated test file. I think I've fixed it now. I'm going to check that the tests are actually running in the CI (running |
32caf58
to
4bd5a78
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.
Some last comments from my side, mostly just nits and a question :)
There's still some duplicate looking code in check_{variants,fields}
, but it's subtly different in places that I'm not sure it's easily refactorable into its own function, so I'm also not sure it's worth blocking the PR over it (but if you have ideas for addressing this, feel free to do that too). There's the other PR which makes parts of check_variant
match the behavior from check_fields
more closely, so it might be easier to refactor it with those changes.
I also did a lintcheck run and there didn't appear to be any FPs (actually there weren't any matches at all, which is not necessarily a bad thing), though only on the 26 default crates
@Alexendoo do you have some other things to comment on that I might have missed?
07c662e
to
a2577a4
Compare
c0d8961
to
e59d512
Compare
I think it makes sense to move the |
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.
Before we can merge this, one last comment about the empty enum test. After this I think we're good. 😄
(Also, the changelog in the description still says that a config option was renamed. Not true anymore)
e59d512
to
80025e0
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.
Alright, this looks ready to be merged 🎉. Thank you for implementing this lint and for your patience!
@bors r+
🤔 @bors ping |
😪 I'm awake I'm awake |
Let's try again? @bors r+ |
add lint for struct field names changelog: [`struct_field_names`]: lint structs with the same pre/postfix in all fields or with fields that are pre/postfixed with the name of the struct. fixes #2555 I've followed general structure and naming from the code in [enum_variants](https://github.com/rust-lang/rust-clippy/blob/b788addfcc955368b9771b77d312c248fab60253/clippy_lints/src/enum_variants.rs) lint, which implements the same logic for enum variants.
💔 Test failed - checks-action_test |
I guess it doesn't like that linebreak after changelog? @jonboh can you try removing that? |
linebreak removed. Thank you for taking the time to review the PR :D |
@bors retry |
add lint for struct field names changelog: [`struct_field_names`]: lint structs with the same pre/postfix in all fields or with fields that are pre/postfixed with the name of the struct. fixes #2555 I've followed general structure and naming from the code in [enum_variants](https://github.com/rust-lang/rust-clippy/blob/b788addfcc955368b9771b77d312c248fab60253/clippy_lints/src/enum_variants.rs) lint, which implements the same logic for enum variants.
💔 Test failed - checks-action_test |
It seems I need to update the book with the new struct fields config parameter. I'll try to submit the change in a few hours |
Yep, just running |
side effect for `enum_variants`: use .first() instead of .get(0) in enum_variants lint move to_camel_case to str_util module move module, enum and struct name repetitions check to a single file `item_name_repetitions` rename enum_variants threshold config option
80025e0
to
8b02dac
Compare
Third time's the charm. @bors retry |
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
🎉 That took a few tries. |
changelog: [
struct_field_names
]: lint structs with the same pre/postfix in all fields or with fields that are pre/postfixed with the name of the struct.fixes #2555
I've followed general structure and naming from the code in enum_variants lint, which implements the same logic for enum variants.