Skip to content

Commit 5986121

Browse files
committed
Run the formatter in CI
Enable running formatter checks in CI. While we are at it add formatter checks to the pre-commit hook.
1 parent e194f0f commit 5986121

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ jobs:
3030
env:
3131
DO_DOCS: true
3232
run: ./contrib/test.sh
33+
- name: Check formatting
34+
env:
35+
DO_FMT: true
36+
run: ./contrib/test.sh
3337

3438
Tests:
3539
name: Tests

contrib/test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ if [ "$DO_ASAN" = true ]; then
9292
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
9393
fi
9494

95+
# Run formatter if told to.
96+
if [ "$DO_FMT" = true ]; then
97+
if [ "$NIGHTLY" = false ]; then
98+
echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)"
99+
exit 1
100+
fi
101+
rustup component add rustfmt
102+
cargo fmt --check
103+
fi
95104

96105
# Bench if told to, only works with non-stable toolchain (nightly, beta).
97106
if [ "$DO_BENCH" = true ]

githooks/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ git diff-index --check --cached $against -- || exit 1
4848

4949
# Check that code lints cleanly.
5050
cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1
51+
52+
# Check that the code formats correctly.
53+
cargo +nightly fmt --check || exit 1

0 commit comments

Comments
 (0)