From 0079ca840ab65a31bb6a3f7ffe4539107cff11f6 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 5 Aug 2024 16:59:57 +0000 Subject: [PATCH] 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. --- CONTRIBUTING.md | 2 +- contrib/run-rustfmt.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 contrib/run-rustfmt.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b8e044d1..38956abf2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,7 +124,7 @@ display fine at any tab-length display setting. We use `rustfmt` to establish uniform coding standards throughout the codebase. Please run ```bash -./ci/rustfmt.sh +./contrib/run-rustfmt.sh ``` before committing and pushing any changes, as compliance will also be checked diff --git a/contrib/run-rustfmt.sh b/contrib/run-rustfmt.sh new file mode 100755 index 000000000..d10975657 --- /dev/null +++ b/contrib/run-rustfmt.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eo pipefail + +# Generate initial exclusion list +#find . -name '*.rs' -type f |sort >rustfmt_excluded_files + +# The +rustversion syntax only works with rustup-installed rust toolchains, +# not with any distro-provided ones. Thus, we check for a rustup install and +# only pass +1.63.0 if we find one. +VERS="" +[ "$(which rustup)" != "" ] && VERS="+1.63.0" + +# Run fmt +TMP_FILE=$(mktemp) +find . -name '*.rs' -type f |sort >$TMP_FILE +for file in $(comm -23 $TMP_FILE rustfmt_excluded_files); do + echo "Formatting $file..." + rustfmt $VERS --edition 2021 $file +done -- 2.39.5