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

Initiate configuration of rustfmt #374

Merged
merged 5 commits into from May 10, 2022
Merged

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Apr 28, 2022

We currently use rustfmt with the default configuration. There is some interest in using rustfmt in the crates lower down the stack but it is contentious and difficult to find a configuration, if one exists, that is 'good' for everyone. By configuring rustfmt in this crate we can reduce the scope of the discussion from 'should we even do this' down to 'this is a good formatting configuration', with the hope that if we can get a good configuration worked out in this crate it will help ease the debate in the others.

To get this started add a default config file and then set two, hopefully non-contentious, config options.

Please note carefully; the first patch changes CI to run linting checks using the nightly toolchain.

Re: edition 2018 changes, there are some changes to imports in the examples/ that appear in this PR that should really be removed altogether, leaving as is so as not to clutter this PR.

@tcharding tcharding force-pushed the rustfmt branch 3 times, most recently from 16a867d to dfc3e76 Compare April 28, 2022 02:41
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

concept ACK. We can merge this right before 2018 bump

.github/workflows/rust.yml Outdated Show resolved Hide resolved
@tcharding
Copy link
Member Author

tcharding commented Apr 28, 2022

Changes in force push:

  • Added initial patch to the PR that does the lint->fmt change.
  • Changes to patch 2 as required be newly added patch 1.
  • No other changes.

@tcharding
Copy link
Member Author

Will require manual configuration of the CI pipeline in order to merge.

@tcharding
Copy link
Member Author

Rebased.

apoelstra
apoelstra previously approved these changes May 3, 2022
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 9c053e5

Nice!

@tcharding
Copy link
Member Author

Rebased and re-did the second two patches i.e., for each, updated the config option, ran cargo +nightly fmt and used the same commit message.

apoelstra
apoelstra previously approved these changes May 10, 2022
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 8e02ed0

@sanket1729
Copy link
Member

There are merge conflicts here. This would need a rebase again :(

We only run the formatter (`cargo fmt`) not the linter (`cargo clippy`).
Use the appropriate term in the test script and the CI configuration.
@tcharding
Copy link
Member Author

Changes in force push:

  • rebased on master, CI workflow had conflicts
  • did formatting in last two patches as before

@sanket1729
Copy link
Member

Will require manual configuration of the CI pipeline in order to merge.

Can you elaborate? Do you mean this would need to be merged in god mode?

@tcharding
Copy link
Member Author

Will require manual configuration of the CI pipeline in order to merge.

Can you elaborate? Do you mean this would need to be merged in god mode?

I don't know what setting has to be changed, I don't have access to settings so I'm going off what was said on another PR/repo when I changed the CI workflow. When a PR changes a workflow job the old one seems to still appear in the checks list on the web interface and the new one does not. Sorry I'm not very knowledgeable with GitHub.

@sanket1729
Copy link
Member

I think there is a bug in current config? See https://github.com/rust-bitcoin/rust-miniscript/actions/runs/2303431754

I don't have access to settings so I'm going off what was said on another PR/repo when I changed the CI workflow

I can set the changes, but I cannot see the options for the fuzz-names in the CI workflow for this PR. Perhaps it is related to the above issue?

Running `rustfmt` with the nightly toolchain allows us to use unstable
options. Users can still run it with the stable toolchain locally and
ignore the warnings.
Generate and add a default configuration file for `rustfmt` using

 rustfmt --print-config default rustfmt.toml

This produces a config file that causes `rustfmt` to make no changes, as
expected, when we run

 cargo +nightly fmt

Please note, the config file includes unstable options which throw
warnings if used without the nightly toolchain.
Configure `group_imports = "StdExternalCrate"`.

The benefit of this option is that it increases uniformity in the code
base over the default "Preserve", while saving devs needing to think
about where they place their import statements (for those that do not
use tooling to add them).
Configure `imports_granularity = "Module"`.

The benefit of this option is that it increases uniformity in the code
base over the default "Preserve" and also, from my personal experience,
it tends to reduce the noise in diffs from adding/removing imports.
@tcharding
Copy link
Member Author

Well done, you were correct. Was missing a run: ./contrib/test.sh line. Thanks

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

reACK 8062016

@sanket1729
Copy link
Member

Verified the diff betwen 4847894 and 8062016.

@sanket1729 sanket1729 merged commit 5c466a8 into rust-bitcoin:master May 10, 2022
@tcharding tcharding deleted the rustfmt branch May 11, 2022 02:16
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