-
Notifications
You must be signed in to change notification settings - Fork 305
Add clippy to CI #448
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 to CI #448
Conversation
apoelstra
left a comment
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.
ACK 5551f2c
|
Needs rebase now, sorry. |
Clippy emits: warning: this import is redundant This is a remnant of edition 2015, now we have edition 2018 we no longer need this import statement.
Clippy emits: warning: statics have by default a `'static` lifetime Static strings no longer need an explicit lifetime, remove it.
Clippy emits: warning: this expression creates a reference which is immediately dereferenced by the compiler Remove the explicit reference.
|
No changes in force push, rebase only, there was a merge conflict in one of the unit tests in commit: |
elichai
left a comment
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.
ACK d81d2fe
githooks/pre-commit
Outdated
| # exit with non-zero status after issuing an appropriate message if | ||
| # it wants to stop the commit. | ||
| # | ||
| # To enable this hook, rename this file to "pre-commit". |
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.
that's already the name of the file?
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.
Nice catch, I modified the whole comment to better describe the hook. Thanks.
Kixunil
left a comment
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 exec should be fixed, I believe.
githooks/pre-commit
Outdated
| exec git diff-index --check --cached $against -- | ||
|
|
||
| # Check that code lints cleanly. | ||
| exec cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings |
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 doesn't work since exec replaces the process (just like the exec syscall) thus this exec never executes
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.
Thanks man, seems I tested whitespace but not clippy before pushing this. Out of interest I tried removing both the execs and adding set -e but that did not work, I then tried the form cmd || exit 1 for both and that works.
src/context.rs
Outdated
| /// ``` | ||
| #[allow(unused_mut)] // Unused when `rand-std` is not enabled. | ||
| #[allow(unused_mut)] // Unused when `rand-std` is not enabled. | ||
| #[allow(clippy::let_and_return)] // Triggers when `rand-std` is not enabled. |
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.
Perhaps cfg_attr to limit the scope? Not a big deal though.
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.
Nice trick! I had to think about your suggestion for a bit then I worked it out
#[cfg_attr(not(feature = "rand-std"), allow(clippy::let_and_return, unused_mut))]For the second time today; thanks for the lesson :)
src/ecdsa/mod.rs
Outdated
| let le_counter = counter.to_le_bytes(); | ||
| for (i, b) in le_counter.iter().enumerate() { | ||
| extra_entropy[i] = *b; | ||
| } |
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 whole chunk could be just extra_entropy[..4].copy_from_slice(&counter.to_le_bytes);
Also below (can't comment there) cast is probably better than as. extra_entropy.as_ptr().cast::<ffi::types::c_void>();
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 used both suggestions, I was unable to justify the as -> cast change in the commit log, can you explain why its better please, just for my learning?
apoelstra
left a comment
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.
ACK d81d2fe
|
Will hold off on merging since @Kixunil's nits look good (and the |
|
|
|
Well, it breaks the main purpose of the pre-commit hook :) but the CI job is not affected. But yes, I see your point. |
fddca7c to
6c6a577
Compare
Since we bumped the MSRV we have `to_le_bytes` available now, use it instead of `mem::transmute`. Remove code comment suggesting to do exactly this and clear clippy warning. While we are at it, use `cast` instead of `as`.
We have a whole bunch of unsafe code that calls down to the FFI layer. It would be nice to have clippy running on CI, these safety docs warnings are prohibiting that. Until we can add the docs add a compiler attribute to allow the lint.
Clippy emits: warning: returning the result of a `let` binding from a block This is due to feature guarded code, add 'allow' attribute. Use `cfg_attr` to restrict the allow to when it is needed. Add the already present `unused_mut` inside the `cfg_attr` guard also.
Clippy emits: warning: manual implementation of `str::repeat` using iterators As suggested, use `"a".repeats()`.
We are explicitly testing various boolean statements, tell clippy to allow less than minimal statements.
In order to keep the codebase linting cleanly add a CI job to run clippy.
Add `githooks` directory and: - Copy the default pre-commit hook into new githooks directory - Add a call to clippy to the pre-commit hook - Add a section to the README instructing devs how to use the new githooks
|
Solid reviewing crew, thank you. Force push includes the various changes above. |
Kixunil
left a comment
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.
ACK 65186e7
apoelstra
left a comment
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.
ACK 65186e7
apoelstra
left a comment
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.
ACK 65186e7
|
Lol, sorry, I meant to test and ack 488. |
65186e732ac229575afd83f5c11bfb794ebc3ca8 Add githooks (Tobin C. Harding) 6d76bd4a8952f0a03f204b8096eaf6f0dc5d40d3 Add clippy to CI (Tobin C. Harding) 9f1ebb93cba87f5d43702a138cdce658fbdd511d Allow nonminimal_bool in unit test (Tobin C. Harding) 685444c34252142a516c3f04c242c73c54c91e8d Use "a".repeats() instead of manual implementation (Tobin C. Harding) 42de876e01071e0992067b88c620667be5b1391b Allow let_and_return for feature guarded code (Tobin C. Harding) d64132cd4b4c03bb08f33cc4f8415669414335b4 Allow missing_safety_doc (Tobin C. Harding) 2cb687fc6999bd38bd3949b0c981e6ffb221b5f9 Use to_le_bytes instead of mem::transmute (Tobin C. Harding) c15b9d26997c062c8bb5f26a3ad8ba2f20a91244 Remove unneeded explicit reference (Tobin C. Harding) 35d59e7cc6954a0109191b2772f0f4a90197ef8c Remove explicit 'static lifetime (Tobin C. Harding) 1a582db16021e696effeb6080d1197a23c620cf2 Remove redundant import (Tobin C. Harding) Pull request description: The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a `githooks` directory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the [open PR](rust-bitcoin/rust-bitcoin#1044) on `rust-bitcoin` that adds githooks _without_ yet adding clippy. **Note**: The new clippy CI job runs and is green :) ACKs for top commit: Kixunil: ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8 apoelstra: ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8 Tree-SHA512: f70a157896ce2a83af8cfc10f2fbacc8f68256ac96ef7dec4d190aa72324b568d2267418eb4fe99099aeda5486957c31070943d7c209973859b7b9290676ccd7
65186e732ac229575afd83f5c11bfb794ebc3ca8 Add githooks (Tobin C. Harding) 6d76bd4a8952f0a03f204b8096eaf6f0dc5d40d3 Add clippy to CI (Tobin C. Harding) 9f1ebb93cba87f5d43702a138cdce658fbdd511d Allow nonminimal_bool in unit test (Tobin C. Harding) 685444c34252142a516c3f04c242c73c54c91e8d Use "a".repeats() instead of manual implementation (Tobin C. Harding) 42de876e01071e0992067b88c620667be5b1391b Allow let_and_return for feature guarded code (Tobin C. Harding) d64132cd4b4c03bb08f33cc4f8415669414335b4 Allow missing_safety_doc (Tobin C. Harding) 2cb687fc6999bd38bd3949b0c981e6ffb221b5f9 Use to_le_bytes instead of mem::transmute (Tobin C. Harding) c15b9d26997c062c8bb5f26a3ad8ba2f20a91244 Remove unneeded explicit reference (Tobin C. Harding) 35d59e7cc6954a0109191b2772f0f4a90197ef8c Remove explicit 'static lifetime (Tobin C. Harding) 1a582db16021e696effeb6080d1197a23c620cf2 Remove redundant import (Tobin C. Harding) Pull request description: The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a `githooks` directory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the [open PR](rust-bitcoin/rust-bitcoin#1044) on `rust-bitcoin` that adds githooks _without_ yet adding clippy. **Note**: The new clippy CI job runs and is green :) ACKs for top commit: Kixunil: ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8 apoelstra: ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8 Tree-SHA512: f70a157896ce2a83af8cfc10f2fbacc8f68256ac96ef7dec4d190aa72324b568d2267418eb4fe99099aeda5486957c31070943d7c209973859b7b9290676ccd7
The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a
githooksdirectory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the open PR onrust-bitcointhat adds githooks without yet adding clippy.Note: The new clippy CI job runs and is green :)