-
Notifications
You must be signed in to change notification settings - Fork 312
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 clippy and rustfmt to CI #143
Conversation
Add clippy check to CI Apply uses correctly Specify runs-on Use checkout specified from check-prettier Try specifying toolchain with clippy as components Apply to correct action Specify nightly without date Use 'rustup component add clippy' instead of toolchain Uses on steps Typo Specify rustfmt and clippy in rust-toolchain file Try only rustfmt Undo Revert rust-toolchain file Add --workspace arg to clippy
Add rustfmt check --
The code changes look great to me. I'll be happy to have these tools keeping our code clean. The |
I'm in favor of adding both, but definitely at least the In the past, I've disabled clippy lints with annotations at the top of the root file i.e. |
I'm surprised that clippy is needed when the rust compiler is so strict. Catching things like impossible conditions should be done by the compiler. |
That's actually a really good point. The I can document using these in both |
vim and vscode are probably the only one we need right now |
I gave it a quick try and didn't have much luck with vscode neither for rustfmt nor clippy. I let you look deeper Stephen and let me know |
Also, to fix your CI, you need to push your Cargo.lock after building it (parachain and also standalone) |
Cargo.lock
Outdated
@@ -9338,8 +9339,7 @@ dependencies = [ | |||
[[package]] | |||
name = "substrate-wasm-builder" | |||
version = "3.0.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "79091baab813855ddf65b191de9fe53e656b6b67c1e9bd23fdcbff8788164684" | |||
source = "git+https://github.com/paritytech/substrate#39278096356942a087213b0f21c976ac100cb8f8" | |||
dependencies = [ |
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.
These changes don't seem relevant to this PR -- is this what you expected, @crystalin ?
This might be suitable for vscode: https://users.rust-lang.org/t/how-to-use-clippy-in-vs-code-with-rust-analyzer/41881 This looks promising for Vim (although I find that https://vimawesome.com/plugin/vim-clippy Another option would be to add a git-commit hook. This looks promising for managing git hooks: |
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 looks good to me!
I agree with Alan that we want to document how to use this with some common IDEs so devs can be maximally productive with it.
Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
This last commit (c9042b3) adds a git pre-commit hook using Once this is initialized, a git pre-commit hook will invoke I would appreciate any feedback on this. This invocation of Also note that removing these hooks is a bit of a pain (if you had no previous hooks set up, you'll want to |
What does it do?
This PR attempts to include both
clippy
andrustfmt
into our CI workflow.What important points reviewers should know?
Please examine the changes closely to ensure they are sane. It would be better to adjust any formatting/linting configuration before merging this.
This PR should leave the code functionally equivalent.
Is there something left for follow-up PRs?
No (not yet)
What alternative implementations were considered?
If we don't like either
rustfmt
orclippy
, we could adopt only one of them.Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?
No
What value does it bring to the blockchain users?
This should improve code quality which should lead to improved developer productivity.
Checklist
Details
This PR introduces
clippy
andrustfmt
into CI.To use these locally, run
cargo clippy
orcargo fmt
respectively. Note that clippy will only produce errors which must be fixed; rustfmt will actually rewrite your code (it is "destructive").cargo fmt -- --check
will prevent this.See 6f4e984 for the changeset introduced by
rustfmt
.Remaining TODO:
clippy
runs off into.cargo/
) when run via CI.rustfmt.toml
previously existed)clippy vs. rustfmt
Find
clippy
here andrustfmt
here.rustfmt
is strictly concerned with stylistic code formatting; this includes such things as when to introduce new lines, where spacing should and should not be, how many parameters can exist on one line, etc. It generally should not produce discernible changes in compiled code.rustfmt's config is controlled by our
.rustfmt.toml
file. This file existed previously to this PR and appears to have been written to agree with.editorconfig
.clippy
is concerned with more logical errors. An example of the type of complaint clippy might produce is comparing0 > someUnsignedInt
, which could never evaluate to true. See a list of clippy's linters here. The defaults forclippy
seem reasonable, but I will have a better feel for this after addressing some of its complaints.