Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add clippy to CI #9694

Merged
merged 24 commits into from
Oct 3, 2021
Merged

add clippy to CI #9694

merged 24 commits into from
Oct 3, 2021

Conversation

gilescope
Copy link
Contributor

@gilescope gilescope commented Sep 4, 2021

This PR enforces the majority of the lints from clippy's correctness category.

Future PRs can gradually turn additional lints on where we all agree there's value in the lint.

@gilescope gilescope added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Sep 4, 2021
@gilescope gilescope requested a review from a team as a code owner September 4, 2021 17:16
@gilescope gilescope changed the title WIP: add clippy to CI add clippy to CI Sep 4, 2021
@gilescope gilescope added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Sep 4, 2021
Copy link
Contributor

@TriplEight TriplEight left a comment

Choose a reason for hiding this comment

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

.gitlab-ci.yml Outdated Show resolved Hide resolved
lints.toml Outdated Show resolved Hide resolved
.gitlab-ci.yml Outdated Show resolved Hide resolved
@gilescope
Copy link
Contributor Author

CI now should have clippy thanks to cumulus: paritytech/scripts#342

@bkchr
Copy link
Member

bkchr commented Sep 19, 2021

I'm personally not convinced about clippy and its value.

People can use clippy locally as part of their IDE and fix what it complains about in their code, but in overall I don't see any need to force everyone to use this.

@gilescope
Copy link
Contributor Author

gilescope commented Sep 19, 2021 via email

@kianenigma
Copy link
Contributor

I'm personally not a fan of Clippy, nor have I ever found a good spot for it in my workflow locally. But I am open to allowing some lints that don't have a huge initial impact and gradually find a balance.

@dvdplm
Copy link
Contributor

dvdplm commented Sep 20, 2021

I like clippy and its community; more than once I've learned about some new Rust feature through its warnings. If we do this sensibly (read: avoiding pedantry) and gradually I have no objections.

Copy link
Contributor

@TriplEight TriplEight left a comment

Choose a reason for hiding this comment

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

Btw why not a toml config?

.maintain/clippy.sh Outdated Show resolved Hide resolved
@gilescope
Copy link
Contributor Author

gilescope commented Sep 20, 2021

Just focusing on the correctness lints. There's a couple of places where we impl Hash explicitly but we rely on the derived PartialEq. That makes for very hard to find bugs in my experience. ( https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq ). That's the kind of lint I'm happy to have turned on.

client/network/src/state_request_handler.rs:81:1
client/network/src/block_request_handler.rs:88:1

Hmm, I think this way round is not so much of a problem - if we were just deriving Hash we could introduce a bug here, but these definitions look ok to me.

@TriplEight
Copy link
Contributor

To be merged after #9637

@gilescope
Copy link
Contributor Author

Someone somewhere asked about how rust analyser would stay in sync with the clippy lints defined in the .sh file.
After a bit of digging through the history ( rust-lang/cargo#5034 ) it looks like we can now define this in rustflags in .cargo/config.toml which should mean that every tool has the same view.

This relies on a compiler patch that landed 8th July 2021.
If people are using an earlier version of the compiler
everything will still work unless they try and run clippy.
client/network/src/block_request_handler.rs Show resolved Hide resolved
client/executor/wasmtime/src/instance_wrapper.rs Outdated Show resolved Hide resolved
client/executor/src/wasm_runtime.rs Outdated Show resolved Hide resolved
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

People can use clippy locally as part of their IDE and fix what it complains about in their code, but in overall I don't see any need to force everyone to use this.

I am in favor on enforcing clippy globally because I never found a way to do exactly this. rust-analyzer annoys me with warnings from the whole workspace no matter in which sub directory I open my IDE in.

.gitlab-ci.yml Outdated Show resolved Hide resolved
.cargo/config.toml Show resolved Hide resolved
@gilescope
Copy link
Contributor Author

gilescope commented Oct 1, 2021

Even clippy critics seem to care about the issues that clippy has raised here, so clippy as currently configured seems to be focusing on the right things and is providing us with additional assurances (while not being too noisy).

I'm going to merge this as there's sufficient thumbs-up thought I do note that people are in two minds about this. Let's try it for a few weeks and see if it causes any disruption. We can rollback easily or mute certain lints if they're not paying their way.

Copy link
Contributor

@TriplEight TriplEight left a comment

Choose a reason for hiding this comment

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

Aight to merge after these nits. Those who will have to rebase on this should not face much trouble.

.gitlab-ci.yml Outdated Show resolved Hide resolved
.gitlab-ci.yml Show resolved Hide resolved
@athei
Copy link
Member

athei commented Oct 1, 2021

It appears that there is support for a clipply.toml: https://github.com/rust-lang/rust-clippy#configuration

Why aren't we using this?

@gilescope
Copy link
Contributor Author

gilescope commented Oct 1, 2021

Clippy.toml only allows you to specify how much cyclometric complexity you're willing to tolerate etc. It does not allow you to specify whether to allow or deny any of the lints. There's a very long thread on this: TL/DR looks like there's a PR to allow common metadata in workspaces; after that they might make it specifiable in Cargo.toml. The reason for Clippy.toml not being in the running is that these clippy allow / deny should be specified in the same way as tuning on/off rustc lints are. (They have been debating this point for 5 years now, meanwhile as of July this year, the .cargo/config.toml workaround is now viable)

@athei
Copy link
Member

athei commented Oct 1, 2021

I see thanks.

Co-authored-by: Denis Pisarev <[email protected]>
@gilescope gilescope merged commit 5413a1f into paritytech:master Oct 3, 2021
ordian added a commit that referenced this pull request Oct 5, 2021
* master: (125 commits)
  Update multiple dependencies (#9936)
  Speed up timestamp generation when logging (#9933)
  First word should be Substrate not Polkadot (#9935)
  Improved file not found error message (#9931)
  don't read events in elections anymore. (#9898)
  Remove incorrect sanity check (#9924)
  Require crypto scheme for `insert-key` (#9909)
  chore: refresh of the substrate_builder image (#9808)
  Introduce block authorship soft deadline (#9663)
  Rework Transaction Priority calculation (#9834)
  Do not propagate host RUSTFLAGS when checking for WASM toolchain (#9926)
  Small quoting comment fix (#9927)
  add clippy to CI (#9694)
  Ensure BeforeBestBlockBy voting rule accounts for base (#9920)
  rm `.maintain` lock (#9919)
  Downstream `node-template` pull (#9915)
  Implement core::fmt::Debug for BoundedVec (#9914)
  Quickly skip invalid transactions during block authorship. (#9789)
  Add SS58 prefix for Automata (#9805)
  Clean up sc-peerset (#9806)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants