-
Notifications
You must be signed in to change notification settings - Fork 346
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
Enforce selected clippy lints, and small style fixes #4570
Conversation
f0c8f9f
to
bbbbc4a
Compare
This is not necessarily related to this PR, but |
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 like most of these, except for the redundant_else
commit (as you foresaw). I highlighted the two that seemed to get a lot worse. The others in that commit seem OKish to change, though I often am not sure about them and I'm not sure it's good to force those changes.
So, I'd prefer dropping that entire commit, but I don't insist on it (especially if the two cases I highlighted can be avoided)
I'm happy with the others, though I'd wait for others to take a look. Thank you!
Another thing to consider is that this will add to headache of us being affected by clippy false-positive bugs. I imagine these checks are less well-tested than the default checks. On the bright side, these used to occur previously, and haven't for the past ~3 months, so perhaps Clippy changed something about their testing. But again, they might be more lax about less frequently used checks. I don't think this is a blocker; if it becomes a problem, we can revert parts of this PR. |
Agreed. The first version of this PR had a |
They are well-tested nontheless: many projects use
New lints must now go (since a few weeks ago) through a FCP (final comment period) before being integrated into Clippy, and must be explicitly approved by one extra member of the Clippy team (in addition to the one approving the PR), and any member of the Clippy team may use a veto. This should lead to an even higher lint quality.
Yes, removing a denying lint is done by removing the corresponding line in the top |
Agreed. As I expected, this was the most controversial lint to enable. I'll remove it. |
03619d0
to
bc0fe69
Compare
591f44c
to
80a57e6
Compare
412ce09
to
e573a49
Compare
I don't have a problem with doing this, although some discussion (on GitHub or if you're in the Discord) beforehand would've been valuable, since this affects all pending PRs. This is similar in style to Matt's one import per line PR. |
That's fair. A heads-up on Discord would have been good, but I also don't think contributors should have to join Discord, so I think it's more important that the PR stays or for at least a day or two to get people a chance to comment. Does 24 hours seem like a reasonable time to you too or do you think we should require a longer time? |
Many files are touched by this PR, but changes are very sparse. I am not sure there will be many conflicts. Moreover, I'm of course ready to wait until some sensible or complex PRs are merged and do the job of rebasing, with jj it's a breeze. I also wanted to get a chance to get it in at the beginning of a cycle, to avoid proposing such a change just before a release in case urgent PRs need to get in, to avoid complicating things if things don't go as smoothly as I expect them to be. |
I think @PhilipMetzger's concern was not with merge conflicts but that we should give people a chance to chime in on style guide changes. |
I think we have a implicit three day period on RFC style changes, so that should be fine.
Its not about conflicts, as you essentially made a LSC without informing anyone and getting appropriate buy-ins, even if the technical steering for the project isn't defined yet. It also makes landing currently approved PRs harder, as we now enforce new clippy checks, which weren't enforced before. Edit: I actually meant this link here https://chromium.googlesource.com/chromium/src/+/HEAD/docs/process/lsc/large_scale_changes.md for LSC, my bad. |
Sounds good. I wasn't actually aware of the 3-day period on RFC-style changes (same as design docs?), but I think you're saying that 24 hours is fine for a style change like this PR? So let's wait at least 5 hours more then, @samueltardieu. |
Sorry, it seems I was unclear. I meant that usually Authors let their RFC like proposals open for discussion for three days, before a decision was made (again, I am recalling this). The no unsafe in I'd like to wait another day, so we give everyone time to react though. |
(Not really specific to this PR) As an experiment, I added a label for this. I've occasionally missed having a way to say that a PR LGTM but I want to give others a chance to look at it. Perhaps a label could work for this. We could also have a convention for how long the label should stay on a PR before it's merged. We could mention this in the label description. I think this could work, but better names or better ideas are of course very welcome. For now, I'll leave the timing to everyone's judgement with the author having the final say (just like we did before without this label). Update: One imperfection in this is that it's unclear whether the PR is waiting for a technical review from some small and specific group of people, or whether it affects everybody. We could additionally have an |
Most collection references implement `.into_iter()` or its mutable version, so it is possible to iterate over the elements without using an explicit method to do so.
`.clone()` is more explicit when we already have an object of the right type.
e573a49
to
3ab3fd0
Compare
Right now, we only use the basic Clippy lints. While many software opt to use
clippy::pedantic
, with sometimes individually disabled restrictions, this would be a bit extreme to do in one step (or to do at all, some lints might be intrusive or opiniated).This PR proposes the activation of selected Clippy lints. Those I have tried so far are:
explicit_iter_loop
: prefer iterating over&collection
rather thancollection.iter()
, this is more compact and idiomaticflat_map_option
: using.flat_map(f)
whenf
returns anOption
is equivalent to using.filter_map(f)
, except that the latter better underlines the filtering aspectimplicit_clone
: using.to_vec()
on aVec
, or.to_owned()
on an owned object can be replaced by.clone()
, which makes it clearer that we already have something of the right type; at least one.clone()
call is even superfluous after doing this transformationneedless_for_each
: for simple loops (one occurrence currently in the code), using an explicitfor
loop is clearer than using.for_each()
(removed after discussion, see below)redundant_else
: we learn very early that usingelse
after a block which returns early is useless. This might be the most contentious lint in this list, as it changes the style a bit.semicolon_if_nothing_returned
: using;
at the end of expressions returning()
when we do not explicitly need this unit value better expresses that we have a statement, not just an expression. It increases style consistency.unlined_format_args
: inline variable names in{}
when interpolating, also for consistency as this is done in 90%+ of the code.Other lints might be of interest of course, but I gave it a first run in order to test the idea, and find some lints that other developers might feel comfortable with.
If I'm not wrong, all those lints are available in the stable compiler used to run Clippy in the CI.