2017-09-01 03:54:15 +03:00
# Grin Style Guide
2017-12-05 03:57:03 +03:00
Grin uses [rustfmt ](https://github.com/rust-lang-nursery/rustfmt ) to maintain consistent formatting.
2017-09-01 03:54:15 +03:00
## Install rustfmt (nightly)
Note: we assume Rust has been installed via [Rustup ](https://www.rustup.rs/ ).
See [build docs ](./build.md ) for more info.
```
2018-03-06 03:53:08 +03:00
rustup component add rustfmt-preview
2017-09-01 03:54:15 +03:00
rustup update
```
## Install git pre-commit hook
There is a basic git [pre-commit ](../.hooks/pre-commit ) hook in the repo.
The pre-commit hook will not prevent commits if style issues are present but it will
indicate any files that need formatting.
2017-12-05 03:57:03 +03:00
To enable this, create a symlink in `.git/hooks` (note the relative path) -
2017-09-01 03:54:15 +03:00
```
cd .git/hooks
ln -s -f ../../.hooks/pre-commit
```
## Running rustfmt
2018-01-30 16:36:18 +03:00
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.
2017-09-01 03:54:15 +03:00
2018-01-30 16:36:18 +03:00
First maybe try a dry-run to see what changes would be made:
`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)