Skip to content

Commit 59e199b

Browse files
authored
Merge pull request #1138 from johannhof/travis-docs
Add instructions on how to run rustfmt on Travis
2 parents 61042e6 + c8e871f commit 59e199b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ diff, replace, overwrite, display, coverage, and checkstyle.
6565
* `overwrite` Overwrites the original files _without_ creating backups.
6666
* `display` Will print the formatted files to stdout.
6767
* `diff` Will print a diff between the original files and formatted files to stdout.
68+
Will also exit with an error code if there are any differences.
6869
* `checkstyle` Will output the lines that need to be corrected as a checkstyle XML file,
6970
that can be used by tools like Jenkins.
7071

@@ -111,6 +112,28 @@ You can run `rustfmt --help` for more information.
111112
* [Atom](atom.md)
112113
* Visual Studio Code using [RustyCode](https://github.com/saviorisdead/RustyCode) or [vsc-rustfmt](https://github.com/Connorcpu/vsc-rustfmt)
113114

115+
## Checking style on a CI server
116+
117+
To keep your code base consistently formatted, it can be helpful to fail the CI build
118+
when a pull request contains unformatted code. Using `--write-mode=diff` instructs
119+
rustfmt to exit with an error code if the input is not formatted correctly.
120+
It will also print any found differences.
121+
122+
A minimal Travis setup could look like this:
123+
124+
```yaml
125+
language: rust
126+
cache: cargo
127+
before_script: (cargo install rustfmt || true)
128+
script:
129+
- |
130+
cargo fmt -- --write-mode=diff &&
131+
cargo build &&
132+
cargo test
133+
```
134+
135+
Note that using `cache: cargo` is optional but highly recommended to speed up the installation.
136+
114137
## How to build and test
115138

116139
`cargo build` to build.

0 commit comments

Comments
 (0)