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

Custom clippy configuration #478

Merged
merged 1 commit into from
Mar 2, 2023
Merged

Custom clippy configuration #478

merged 1 commit into from
Mar 2, 2023

Conversation

jrray
Copy link
Collaborator

@jrray jrray commented Aug 26, 2022

This is a step towards having some coding and style conventions for this project "in writing" that we can all discuss and agree on, focusing on two things have been a frequent point of contention in code reviews.

The use of bools in function parameters can be monitored by clippy. This is a "pedantic" check so it is not enabled by default. I put the attr in every lib.rs to enable it. Our codebase passes with this set to 1, with one exception, where the warning has been supressed. I agree with the sentiment of the clippy lint text, "calls to such functions [with excessive use of bools] are confusing and error prone," particularly if there are multiple consecutive bool arguments. But rather than banning bool arguments entirely, allowing a single bool argument avoids the confusing argument order problem.

The threshold for too many arguments is enabled by default, but has a default limit of 7. For our codebase, 5 is the lowest it can go without triggering any warnings. My personal preference is to not try to go lower than 5.

Interestingly, this was the #2 most ignored lint: rust-lang/rust-clippy#7666 As noted in the comments, this is most likely due to new constructors for complex structs requiring many arguments.

@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

Merging #478 (d542ae8) into master (89226f6) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #478   +/-   ##
=======================================
  Coverage   58.02%   58.02%           
=======================================
  Files         216      216           
  Lines       15942    15942           
=======================================
  Hits         9250     9250           
  Misses       6692     6692           
Impacted Files Coverage Δ
crates/parsedbuf/src/lib.rs 76.92% <ø> (ø)
crates/spfs-cli/cmd-clean/src/cmd_clean.rs 0.00% <ø> (ø)
crates/spfs-cli/cmd-enter/src/cmd_enter.rs 0.00% <ø> (ø)
crates/spfs-cli/cmd-join/src/cmd_join.rs 0.00% <ø> (ø)
crates/spfs-cli/cmd-monitor/src/cmd_monitor.rs 0.00% <ø> (ø)
crates/spfs-cli/main/src/bin.rs 0.00% <ø> (ø)
crates/spk-cli/cmd-render/src/cmd_render.rs 0.00% <ø> (ø)
crates/spk-cli/common/src/lib.rs 0.00% <ø> (ø)
crates/spk-solve/src/lib.rs 100.00% <ø> (ø)
crates/spk/src/cli.rs 0.00% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@rydrman rydrman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, ya I think that this is a great idea - thanks! I'm also in favour of the rules that you laid out initially. Obviously, I would try to go lower than 5 if I could, but I can agree that it's probably a more reasonable hard rule, as you say

@jrray jrray changed the title RFC: Custom clippy configuration Custom clippy configuration Feb 25, 2023
@@ -34,6 +37,7 @@ fn make_tag_part(pieces: Vec<&str>) -> Option<Vec<BuildKeyVersionNumberPiece>> {

// For making test case results
#[allow(clippy::too_many_arguments)]
#[allow(clippy::fn_params_excessive_bools)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing this here as the one special case in the code base.

#![deny(unsafe_op_in_unsafe_fn)]
#![warn(clippy::fn_params_excessive_bools)]

use std::sync::Arc;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a misplaced import here.

@jrray jrray requested a review from rydrman February 25, 2023 01:07
@jrray
Copy link
Collaborator Author

jrray commented Feb 25, 2023

@rydrman please do another look before I merge this. I added comments to the changes that aren't just adding deny/warn to all the files.

Copy link
Collaborator

@rydrman rydrman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that we could put the lint attributes at the crate level and not need to apply them to every module, or am I misreading these diffs?

@jrray
Copy link
Collaborator Author

jrray commented Feb 25, 2023 via email

@jrray
Copy link
Collaborator Author

jrray commented Feb 25, 2023 via email

@rydrman
Copy link
Collaborator

rydrman commented Feb 25, 2023

I think it would just be every lib.rs file

@jrray
Copy link
Collaborator Author

jrray commented Feb 25, 2023 via email

Enable checking of excessive bool parameters in all crates, and limit to 1.
Limit the number of arguments to 5.

Signed-off-by: J Robert Ray <jrray@jrray.org>
@jrray
Copy link
Collaborator Author

jrray commented Feb 27, 2023

I've taken the directives out of most files. The nice thing about having it in every file is that it is straightforward to verify that the directives are present and active in every file.

@jrray jrray merged commit 4096f42 into master Mar 2, 2023
@jrray jrray deleted the clippy-config branch March 2, 2023 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants