Rust-clippy: Provide an easy way for contributors to run cargo fmt like it's executed on CI

Created on 2 Mar 2019  路  6Comments  路  Source: rust-lang/rust-clippy

As pointed out by @flip1995 in https://github.com/rust-lang/rust-clippy/pull/3824#r261652006, we currently don't have an easy way to run rustfmt on the tests locally like we do on CI.

What we are doing on CI currently:

https://github.com/rust-lang/rust-clippy/blob/8dfabdf11c6cdaffd7c6e6552a6ead8d52c49b10/.travis.yml#L24

https://github.com/rust-lang/rust-clippy/blob/8dfabdf11c6cdaffd7c6e6552a6ead8d52c49b10/ci/base-tests.sh#L26

https://github.com/rust-lang/rust-clippy/blob/8dfabdf11c6cdaffd7c6e6552a6ead8d52c49b10/ci/base-tests.sh#L53-L78

It would be nice if we could extract that into a separate script so that people can use to format their tests locally, instead of waiting for CI.

Some things to consider when doing this:

  • The script also needs to add the rustfmt component if it isn't present locally
  • We use rustfmt instead of cargo fmt for the test formatting because of https://github.com/rust-lang/rustfmt/issues/1820
  • To make it idempotent, the new script should automatically detect the 'current' toolchain and switch back to it after the formatting script has finished (instead of switching to master)
  • Unlike a fresh VM on CI, We can't just use rustup override set nightly, because that doesn't update the locally installed nightly rust. We should probably pin to a specific nightly instead and update the version from time to time.
  • Using a shell script will not work cross-platform but I think doing it in Rust might be too much work?
L-enhancement

Most helpful comment

I'm working on adding a clippy dev subcommand to do this.

I'm don't think the command should install/update toolchains/components by default (especially if we want to run it from a test) but I'll provide an option to do that and error out if the required toolchains/components aren't installed and up to date.

All 6 comments

If we want to provide a cargo format subcommand instead of a shell script, then it might also be worth to look at how rust-analyzer did it: https://github.com/rust-analyzer/rust-analyzer/pull/163.

I'm working on adding a clippy dev subcommand to do this.

I'm don't think the command should install/update toolchains/components by default (especially if we want to run it from a test) but I'll provide an option to do that and error out if the required toolchains/components aren't installed and up to date.

friendly ping @mikerite: did you make some progress on this?

Thanks for the ping.

I didn't get very far and I haven't looked at this in weeks. It's fine by me if someone else wants to do this. Otherwise, I'll try to make some progress this weekend.

I've got something ready but I'll wait until the build is fixed before submitting the PR.

Closing this - thanks to @mikerite we now have util/dev fmt which has been working great :confetti_ball:

Was this page helpful?
0 / 5 - 0 ratings