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

Enabe clippy on CI #1061

Merged
merged 10 commits into from Jun 23, 2022
Merged

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Jun 23, 2022

We are almost ready to enable clippy on CI!

First clear a few remaining warnings from feature gated code. Then add a CI job to run clippy using --all-features (note no --all-targets). Next add githooks directory (this is the patch from https://github.com/rust-bitcoin/rust-bitcoin/pull/1044/commits). Finally add cargo clippy to the pre-commit hook.

EDIT: I just realized the running of clippy could have been done in test.sh instead of as a github action. Does that matter?

clippy emits two warnings of form:

 warning: redundant field names in struct initialization

Remove the redundant field names.
clippy emits:

  warning: this `else { if .. }` block can be collapsed

In this instance the code is more readable how it is, we should ignore
clippy.

Add compiler directive to quieten warning.
clippy emits a bunch of:

 warning: statics have by default a `'static` lifetime

Remove the unnecessary 'static lifetimes.
clippy emits a bunch of:

 warning: digits grouped inconsistently by underscores

We have a custom grouping elsewhere in this file

  10_000_000_00 sats == 10 BTC

Fix up all instances of large sats amount to uniformly using this format
and add compiler directives where needed to shoosh clippy.
clippy emits:

 warning: this expression creates a reference which is immediately
 dereferenced by the compiler

As suggested, remove the explicit reference.
clippy emits:

 warning: using `clone` on type `blockdata::transaction::OutPoint` which
 implements the `Copy` trait

Remove unneeded call to `clone`.
clippy emits:

  warning: question mark operator is useless here

As suggested, remove the `?` operator.
Add a clippy configuration file configuring the MSRV. Add a github
actions job to run clippy on CI.

Please note the job does _not_ use `--all-targets` because doing so
causes:
```
error[E0554]: `#![feature]` may not be used on the stable release channel
--> src/lib.rs:46:54
|
46 | #![cfg_attr(all(test, feature = "unstable"), feature(test))]
```
Add a `githooks` directory. Copy the sample pre-commit hook into it.
Add a section to the README explaining how to take advantage of the
githooks.

The sample pre-commit hook includes checks for trailing whitespace that
we are seeing occasionally in PRs.

Done in preparation for adding a clippy githook.
We have a `pre-commit` githook, add to it a call to `cargo clippy`.
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK e2e4650

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK e2e4650

Not sure how liberal we want to be with allows. The digits one looks reasonable, collapsible if looks not that definite. Wouldn't block this PR but in general I'd like to see as little allows as possible.

@apoelstra
Copy link
Member

I think we should be pretty liberal. It is better than our previous policy of never using clippy.

@apoelstra apoelstra merged commit cf5503a into rust-bitcoin:master Jun 23, 2022
@tcharding tcharding deleted the 06-23-enable-clippy-ci branch June 23, 2022 23:38
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
e2e4650 Add clippy to pre-commit githook (Tobin C. Harding)
820adc0 Add githooks directory (Tobin C. Harding)
668b37a Enable clippy on CI (Tobin C. Harding)
a2a54b3 Remove unnecessary ? operator (Tobin C. Harding)
67ed8f6 Remove unneeded clone (Tobin C. Harding)
eccd401 Remove unneeded reference (Tobin C. Harding)
fd4239f Use custom digit grouping (Tobin C. Harding)
acd551e Remove unnecessary 'static lifetime (Tobin C. Harding)
3102a48 Allow clippy::collapsible_else_if (Tobin C. Harding)
63f4ff6 Remove redundant field names (Tobin C. Harding)

Pull request description:

  We are almost ready to enable clippy on CI!

  First clear a few remaining warnings from feature gated code. Then add a CI job to run clippy using `--all-features` (note no `--all-targets`). Next add githooks directory (this is the patch from https://github.com/rust-bitcoin/rust-bitcoin/pull/1044/commits). Finally add `cargo clippy` to the pre-commit hook.

  EDIT: I just realized the running of clippy could have been done in `test.sh` instead of as a github action. Does that matter?

ACKs for top commit:
  apoelstra:
    ACK e2e4650
  Kixunil:
    ACK e2e4650

Tree-SHA512: c78cb78973d3935e5be7908eec7d6ffaa7989724b3e29551b9fa2cb35df1f39574e31e5cc93fdfb32b35039ac9dac5c080ae4287a1e6979dd076bab56e6eda1b
@Kixunil Kixunil added this to the 0.29.0 milestone Aug 1, 2022
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.

None yet

3 participants