From 897a91b350f54f7b75aa81ba0298236961780f0d Mon Sep 17 00:00:00 2001 From: Michael Wolf Date: Thu, 7 Dec 2023 09:53:21 -0600 Subject: [PATCH] Bake in support for rustfmt --- _reformat-common.bash | 4 ++++ rustfmt.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 rustfmt.sh diff --git a/_reformat-common.bash b/_reformat-common.bash index 6e73b87..bec6707 100644 --- a/_reformat-common.bash +++ b/_reformat-common.bash @@ -147,6 +147,8 @@ function sniff_file_type() { file_type="dart" elif [[ $ff = *.pl ]]; then file_type="perl" + elif [[ $ff = *.rs ]] ; then + file_type="rust" fi echo $file_type @@ -191,6 +193,8 @@ function choose_wrapper() { out="$WF_ROOT"/./isort-and-black.sh elif [[ $file_type == "golang" ]]; then out="$WF_ROOT"/./gofmt.sh + elif [[ $file_type == "rust" ]] ; then + out="$WF_ROOT"/./rustfmt.sh elif [[ $file_type == "dart" ]]; then out="$WF_ROOT"/./dart_format.sh else diff --git a/rustfmt.sh b/rustfmt.sh new file mode 100755 index 0000000..42b790f --- /dev/null +++ b/rustfmt.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -uo pipefail +IFS=$'\n\t' + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "$DIR/_reformat-common.bash" + +log "in rustfmt.sh" + +set -e + +file="$1" + +log what + +pushd "$(dirname "$file")" 2>&1 + +if [[ "$WOULD_REFORMAT" = "would_reformat" ]]; then + +log beavis + + set +e + out=$(rustfmt --check "$file" 2>&1 >/dev/null) + retval="$?" + set -e + +log got back retval $retval + + exit "$retval" +fi + +if [[ "$WOULD_REFORMAT" = "do_reformat" ]]; then + +log in do reformat mode + + out=$(rustfmt "$file" 2>&1 >/dev/null) + retval="$?" + + echo "$out" + +log $out + + exit "$retval" +fi + +log are we here now + +exit 255