mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 12:56:48 +00:00
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
|
@echo "" # Add a blank line
|
||||||
@cd docs && mdbook build # Build mdBook
|
@cd docs && mdbook build # Build mdBook
|
||||||
|
|
||||||
|
format:
|
||||||
|
./tools/format_all.sh
|
||||||
|
|
||||||
check:
|
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
|
@cargo kclippy -- -D warnings # Make build fail if any warnings are found by rustc and clippy
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
3
rustfmt.toml
Normal file
3
rustfmt.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
imports_granularity="Crate"
|
||||||
|
group_imports="StdExternalCrate"
|
||||||
|
reorder_imports=true
|
55
tools/format_all.sh
Executable file
55
tools/format_all.sh
Executable file
@ -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…
x
Reference in New Issue
Block a user