Add rustfmt.toml configuration to adjust the format of imports
This commit is contained in:
parent
22c2cebdec
commit
92e488e727
5
Makefile
5
Makefile
|
@ -130,8 +130,11 @@ docs:
|
|||
@echo "" # Add a blank line
|
||||
@cd docs && mdbook build # Build mdBook
|
||||
|
||||
format:
|
||||
./tools/format_all.sh
|
||||
|
||||
check:
|
||||
@cargo fmt --check # Check Rust format issues
|
||||
./tools/format_all.sh --check # Check Rust format issues
|
||||
@cargo kclippy -- -D warnings # Make build fail if any warnings are found by rustc and clippy
|
||||
|
||||
clean:
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
imports_granularity="Crate"
|
||||
group_imports="StdExternalCrate"
|
||||
reorder_imports=true
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/bash
|
||||
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
WORKSPACE_ROOT="$(dirname "$(readlink -f "$0")")/.."
|
||||
|
||||
EXCLUDED_CRATES=$(sed -n '/^\[workspace\]/,/^\[.*\]/{/exclude = \[/,/\]/p}' "$WORKSPACE_ROOT/Cargo.toml" | grep -v "exclude = \[" | tr -d '", \]')
|
||||
|
||||
|
||||
CHECK_MODE=false
|
||||
|
||||
if [ "$#" -eq 1 ]; then
|
||||
if [ "$1" == "--check" ]; then
|
||||
CHECK_MODE=true
|
||||
else
|
||||
echo "Error: Invalid argument. Only '--check' is allowed."
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$#" -gt 1 ]; then
|
||||
echo "Error: Too many arguments. Only '--check' is allowed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $WORKSPACE_ROOT
|
||||
if [ "$CHECK_MODE" = true ]; then
|
||||
cargo fmt --check
|
||||
else
|
||||
cargo fmt
|
||||
fi
|
||||
|
||||
for CRATE in $EXCLUDED_CRATES; do
|
||||
CRATE_DIR="$WORKSPACE_ROOT/$CRATE"
|
||||
|
||||
# `cargo-component` crate currently is pinned to use Rust nightly-2023-02-05 version,
|
||||
# and when using this script in the current Docker environment, it will
|
||||
# additionally download this version of Rust.
|
||||
# Here temporarily skip processing this crate for now considering that this crate
|
||||
# is not currently in use or under development.
|
||||
case "$CRATE" in
|
||||
*cargo-component*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -d "$CRATE_DIR" ]; then
|
||||
if [ "$CHECK_MODE" = true ]; then
|
||||
(cd "$CRATE_DIR" && cargo fmt --check)
|
||||
else
|
||||
(cd "$CRATE_DIR" && cargo fmt)
|
||||
fi
|
||||
else
|
||||
echo "Directory for crate $CRATE does not exist"
|
||||
fi
|
||||
done
|
||||
|
Loading…
Reference in New Issue