Skip to content

Commit 0d2fe67

Browse files
authored
Merge pull request #3226 from TheBlueMatt/2024-08-rustfmt-contrib
Add a script to automatically `rustfmt` all required files
2 parents 8eff650 + 4c650b9 commit 0d2fe67

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
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

ci/rustfmt.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -eox pipefail
33

4+
export LC_ALL=C
5+
46
# Generate initial exclusion list
57
#find . -name '*.rs' -type f |sort >rustfmt_excluded_files
68

contrib/run-rustfmt.sh

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

0 commit comments

Comments
 (0)