Skip to content

Commit

Permalink
static_tests: Add test for Rust code formatting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Oct 2, 2024
1 parent 505433b commit 20880fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions dist/tools/cargo-checks/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

set -eu

FAILURES=""

# This is a Make based environment, therefore we don't have funny names to take
# care of, and anyone who can cause commands to be run by injecting files can
# just as well modify the scripts being run. (Otherwise we'd need to go through
# a less readable print0 / read).
for CARGOTOML in `find -name Cargo.toml`

Check warning on line 11 in dist/tools/cargo-checks/check.sh

View workflow job for this annotation

GitHub Actions / static-tests

For loops over find output are fragile. Use find -exec or a while read loop. [SC2044]

Check warning on line 11 in dist/tools/cargo-checks/check.sh

View workflow job for this annotation

GitHub Actions / static-tests

Some finds don't have a default path. Specify '.' explicitly. [SC2185]

Check warning on line 11 in dist/tools/cargo-checks/check.sh

View workflow job for this annotation

GitHub Actions / static-tests

Use $(...) notation instead of legacy backticks `...`. [SC2006]
do
if cargo fmt --quiet --check --manifest-path "${CARGOTOML}"; then
continue
else
FAILURES="${FAILURES} ${CARGOTOML%Cargo.toml}"
fi
done

if [ x"" != x"${FAILURES}" ]; then
echo "Some Rust files are following rustfmt, in particular in:"
echo "${FAILURES}"
echo "You can format the code locally using:"
echo
echo "find -name Cargo.toml -exec cargo fmt --manifest-path '{}' ';'"
if [ ! -z "${GITHUB_RUN_ID:-}" ]; then

Check warning on line 26 in dist/tools/cargo-checks/check.sh

View workflow job for this annotation

GitHub Actions / static-tests

Use -n instead of ! -z. [SC2236]
echo
echo "The author of this test regrets not knowing how to provide an easy way to just click a button here that provides the right fixup commits."
fi
exit 1
fi
1 change: 1 addition & 0 deletions dist/tools/ci/static_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ run ./dist/tools/buildsystem_sanity_check/check.sh
run ./dist/tools/feature_resolution/check.sh
run ./dist/tools/boards_supported/check.sh
run ./dist/tools/codespell/check.sh
run ./dist/tools/cargo-checks/check.sh
if [ -z "${GITHUB_RUN_ID}" ]; then
run ./dist/tools/uncrustify/uncrustify.sh --check
else
Expand Down

0 comments on commit 20880fe

Please sign in to comment.