mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
git pre-commit hook to run rustfmt on modified files (#110)
* git pre-commit hook to run rustfmt on modified files * add docs for rustfmt * add CONTRIBUTING file
This commit is contained in:
parent
7b12746a1f
commit
510d7fc331
5 changed files with 109 additions and 5 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
||||||
*.swp
|
*.swp
|
||||||
.*
|
.DS_Store
|
||||||
|
.grin
|
||||||
|
.grin2
|
||||||
target
|
target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
**.iml
|
**.iml
|
||||||
|
|
50
.hooks/pre-commit
Executable file
50
.hooks/pre-commit
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright 2017 The Grin Developers
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
cargo +nightly fmt -- --version &>/dev/null
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
printf "[pre_commit] \033[0;31merror\033[0m: \"cargo +nightly fmt\" not available?\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
result=0
|
||||||
|
problem_files=()
|
||||||
|
|
||||||
|
printf "[pre_commit] rustfmt "
|
||||||
|
for file in $(git diff --name-only --cached); do
|
||||||
|
if [ ${file: -3} == ".rs" ]; then
|
||||||
|
cargo +nightly fmt -- --skip-children --write-mode=diff $file &>/dev/null
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
problem_files+=($file)
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $result != 0 ]; then
|
||||||
|
printf "\033[0;31mfail\033[0m \n"
|
||||||
|
printf "[pre_commit] the following files need formatting: \n"
|
||||||
|
|
||||||
|
for file in $problem_files; do
|
||||||
|
printf " cargo +nightly fmt -- $file\n"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
printf "\033[0;32mok\033[0m \n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
# to actually fail the build on rustfmt failure -
|
||||||
|
# exit $result
|
16
CONTRIBUTING.md
Normal file
16
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Find an area you can help with and do it. Open source is about collaboration and open participation. Try to make your code look like what already exists and submit a pull request. If you're looking for additional ideas, the code includes `TODO` comments for minor to major improvements. Grep is your friend.
|
||||||
|
|
||||||
|
Additional tests are rewarded with an immense amount of positive karma. So is documentation.
|
||||||
|
|
||||||
|
Find us:
|
||||||
|
|
||||||
|
* Chat: [Gitter](https://gitter.im/grin_community/Lobby).
|
||||||
|
* Mailing list: join the [~MimbleWimble team](https://launchpad.net/~mimblewimble) and subscribe on Launchpad.
|
||||||
|
|
||||||
|
## Style Guide
|
||||||
|
|
||||||
|
For info on the Grin style guide, see the [style docs](doc/style.md).
|
||||||
|
|
||||||
|
Grin leverages `rustfmt` to maintain consistent formatting (and a [git commit hook](doc/style.md) to run it).
|
|
@ -16,13 +16,11 @@ To learn more, read our [introduction to MimbleWimble and Grin](doc/intro.md).
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
Grin is still an infant, much is left to be done and contributions are welcome (see below). Check our [mailing list archives](https://lists.launchpad.net/mimblewimble/) for the latest status.
|
Grin is still an infant, much is left to be done and [contributions](CONTRIBUTING.md) are welcome (see below). Check our [mailing list archives](https://lists.launchpad.net/mimblewimble/) for the latest status.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Find an area you can help with and do it. Open source is about collaboration and open participation. Try to make your code look like what already exists and submit a pull request. If you're looking for additional ideas, the code includes TODO comments for minor to major improvements. Grep is your friend.
|
To get involved, read our [contributing docs](CONTRIBUTING.md).
|
||||||
|
|
||||||
Additional tests are rewarded with an immense amount of positive karma. So is documentation.
|
|
||||||
|
|
||||||
Find us:
|
Find us:
|
||||||
|
|
||||||
|
|
38
doc/style.md
Normal file
38
doc/style.md
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# Grin Style Guide
|
||||||
|
|
||||||
|
Grin uses [rustfmt](https://github.com/rust-lang-nursery/rustfmt) to maintain consist formatting.
|
||||||
|
|
||||||
|
## Install rustfmt (nightly)
|
||||||
|
|
||||||
|
Note: we assume Rust has been installed via [Rustup](https://www.rustup.rs/).
|
||||||
|
See [build docs](./build.md) for more info.
|
||||||
|
|
||||||
|
rustfmt itself requires the nightly toolchain -
|
||||||
|
|
||||||
|
```
|
||||||
|
rustup update
|
||||||
|
rustup install nightly
|
||||||
|
rustup run nightly cargo install rustfmt-nightly
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
To enable this create a symlink in `.git/hooks` (note the relative path) -
|
||||||
|
|
||||||
|
```
|
||||||
|
cd .git/hooks
|
||||||
|
ln -s -f ../../.hooks/pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running rustfmt
|
||||||
|
|
||||||
|
To run rustfmt against a single file in grin -
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo +nightly fmt -- ./core/src/lib.rs
|
||||||
|
```
|
Loading…
Reference in a new issue