-
Notifications
You must be signed in to change notification settings - Fork 281
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
Add clippy to CI #448
Conversation
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: |
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.
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 exec
s 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
@@ -191,7 +188,8 @@ mod alloc_only { | |||
/// ctx.seeded_randomize(&seed); | |||
/// # } | |||
/// ``` | |||
#[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_bytes : [u8; 4] = mem::transmute(le_counter); | ||
for (i, b) in le_counter_bytes.iter().enumerate() { | ||
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?
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. |
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
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
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. |
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 onrust-bitcoin
that adds githooks without yet adding clippy.Note: The new clippy CI job runs and is green :)