Added format check for Rust code.

This commit is contained in:
arch-enemy 2023-01-16 15:36:43 +01:00
parent c9a82633a8
commit ed752f447d

View File

@ -8,13 +8,15 @@ else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
RUST_CHECKED=false
checkBash()
{
local file="$1"
echo "checking for 'version' in $file"
now=$(date +'%Y-%m-%d %R')
sed -i "s/version: .*/version: $now/" "$file"
sed -i "s/Version: .*/Version: $now/" "$file"
sed -i "s/version: 2023-01-16 15:36
sed -i "s/Version: 2023-01-16 15:36
git add "$file"
}
@ -41,6 +43,22 @@ checkJavaFormat()
fi
}
checkRustFormat()
{
if [ "$RUST_CHECKED" == "false" ]; then
echo "checking rust code"
command -v cargo || { echo -e "\e[31mcargo not found!\e[0m"; exit 1; }
# diff=$(cargo fmt -- --check)
cargo fmt -- --check
result=$?
if [[ $result -ne 0 ]]; then
echo -e "\e[31mThere are some code style issues, run 'cargo fmt' first."
exit 1
fi
RUST_CHECKED=true
fi
}
for FILE in $(exec git diff --cached --name-only --diff-filter=ACMR) ; do
# Fix them!
case $FILE in
@ -52,6 +70,9 @@ for FILE in $(exec git diff --cached --name-only --diff-filter=ACMR) ; do
checkJavaFormat "$FILE"
git add "$FILE"
;;
*.rs)
checkRustFormat
;;
*.sh|*.profile)
checkBash "$FILE"
;;