Skip to content

Commit 0079ca8

Browse files
committed
Add a script to automatically rustfmt all required files
As we now require `rustfmt` pass on a subset of our files, its helpful to have a script which will automatically format any required files so that contributors don't need to think too hard about it.
1 parent c7419b4 commit 0079ca8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ display fine at any tab-length display setting. We use `rustfmt` to establish
124124
uniform coding standards throughout the codebase. Please run
125125

126126
```bash
127-
./ci/rustfmt.sh
127+
./contrib/run-rustfmt.sh
128128
```
129129

130130
before committing and pushing any changes, as compliance will also be checked

contrib/run-rustfmt.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Generate initial exclusion list
5+
#find . -name '*.rs' -type f |sort >rustfmt_excluded_files
6+
7+
# The +rustversion syntax only works with rustup-installed rust toolchains,
8+
# not with any distro-provided ones. Thus, we check for a rustup install and
9+
# only pass +1.63.0 if we find one.
10+
VERS=""
11+
[ "$(which rustup)" != "" ] && VERS="+1.63.0"
12+
13+
# Run fmt
14+
TMP_FILE=$(mktemp)
15+
find . -name '*.rs' -type f |sort >$TMP_FILE
16+
for file in $(comm -23 $TMP_FILE rustfmt_excluded_files); do
17+
echo "Formatting $file..."
18+
rustfmt $VERS --edition 2021 $file
19+
done

0 commit comments

Comments
 (0)