diff --git a/.gitignore b/.gitignore index 56b3fa227..c04c04507 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.swp -.* +.DS_Store +.grin +.grin2 target Cargo.lock **.iml diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 000000000..39cfd9d02 --- /dev/null +++ b/.hooks/pre-commit @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..e3b283c9a --- /dev/null +++ b/CONTRIBUTING.md @@ -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). diff --git a/README.md b/README.md index 6c02301a5..6c6b436c7 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,11 @@ To learn more, read our [introduction to MimbleWimble and Grin](doc/intro.md). ## 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 -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. +To get involved, read our [contributing docs](CONTRIBUTING.md). Find us: diff --git a/doc/style.md b/doc/style.md new file mode 100644 index 000000000..18f8a23c3 --- /dev/null +++ b/doc/style.md @@ -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 +```