mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
rustfmt install instruction gotcha (#663)
* rustfmt install instruction gotcha rustfmt stopped working for me. It turns out people started having trouble with this last year already https://github.com/rust-lang-nursery/rustfmt/issues/2304 * rustfmt on a single file now works! Secrets inside After `rustup component add rustfmt-preview` I get rustfmt as a command in my terminal. `rustfmt --help` reveals --write-mode [replace|overwrite|display|plain|diff|coverage|checkstyle] and we've been using the default which is either `overwrite` or `replace` (depending on rustfmt version) and this was changing a bunch of files and a messed up workflow. * Newcomer-friendly explanation how to use `rustfmt`
This commit is contained in:
parent
5dce526f90
commit
765996a630
1 changed files with 18 additions and 4 deletions
22
doc/style.md
22
doc/style.md
|
@ -15,6 +15,8 @@ rustup install nightly
|
||||||
rustup run nightly cargo install rustfmt-nightly
|
rustup run nightly cargo install rustfmt-nightly
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you still get problems with running `cargo +nightly fmt`, you might need to also do `rustup component add rustfmt-preview` (see [more info](https://github.com/rust-lang-nursery/rustfmt/issues/2304))
|
||||||
|
|
||||||
## Install git pre-commit hook
|
## Install git pre-commit hook
|
||||||
|
|
||||||
There is a basic git [pre-commit](../.hooks/pre-commit) hook in the repo.
|
There is a basic git [pre-commit](../.hooks/pre-commit) hook in the repo.
|
||||||
|
@ -31,8 +33,20 @@ ln -s -f ../../.hooks/pre-commit
|
||||||
|
|
||||||
## Running rustfmt
|
## Running rustfmt
|
||||||
|
|
||||||
To run rustfmt against a single file in grin -
|
To run rustfmt against a single file, this __new__ command works with latest rust and after having done `rustup component add rustfmt-preview` and by setting --write-mode it doesn't overwrite files.
|
||||||
|
|
||||||
```
|
First maybe try a dry-run to see what changes would be made:
|
||||||
cargo +nightly fmt -- ./core/src/lib.rs
|
`rustfmt --write-mode diff -- client.rs`
|
||||||
```
|
|
||||||
|
Then if you don't want to do any other cleanups manually, make rustfmt make the changes
|
||||||
|
|
||||||
|
`rustfmt -- client.rs`
|
||||||
|
|
||||||
|
and add that as a separate commit at the end of your Pull Request.
|
||||||
|
|
||||||
|
|
||||||
|
The old method would typically change formatting in _nearly every file_ in the grin repo. If you feel adventurous, try this:
|
||||||
|
|
||||||
|
`cargo +nightly fmt -- ./core/src/lib.rs`
|
||||||
|
|
||||||
|
(and please take care, since the ending `-- file/names.rs` actually doesn't have any effect)
|
||||||
|
|
Loading…
Reference in a new issue