Skip to content

Commit 960ff16

Browse files
committed
Add rustfmt configuration and enforce in CI
This prevents any dummies like me from accidentally having a different rustfmt configuration picked up from a parent directory, since rustfmt will scan all the way up to the root directory to find one. It will also ensure that CI builds will break if misformatted code is uploaded. To fail early and avoid unnecessary cycles of bad formatting being committed and then fixed, it is a good idea to add a `.git/hooks/pre-commit` file locally that checks staged files for formatting errors: ```sh git diff --name-only --cached -z '*.rs' |xargs -0 rustfmt --check || exit 1 ```
1 parent 33a3dfe commit 960ff16

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.github/workflows/main.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
features:
1919
- name: all features
2020
value: --all-features
21+
check_formatting: True
2122
- name: no_std
2223
value: --no-default-features --manifest-path binrw/Cargo.toml
2324
steps:
@@ -29,7 +30,15 @@ jobs:
2930
profile: minimal
3031
toolchain: stable
3132
override: true
32-
components: clippy
33+
components: clippy, rustfmt
34+
- name: Check formatting
35+
# There is no reason to check formatting more than once since it is
36+
# a syntax check that does not change depending upon compiler features
37+
if: matrix.features.check_formatting
38+
uses: actions-rs/cargo@v1
39+
with:
40+
command: fmt
41+
args: -- --check
3342
- name: Run clippy
3443
uses: actions-rs/cargo@v1
3544
with:

rustfmt.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# rustfmt will search all the way up the directory tree to find a config
2+
# file. This file stops rustfmt from going beyond the top of the repo.
3+
# It is intentionally empty.

0 commit comments

Comments
 (0)