From bdd4f5c67453056bc91b965e77d643bfeeba2cce Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 15 May 2024 13:20:42 +0100 Subject: [PATCH] Add rustfmt.toml to standardize formatting Signed-off-by: Jorge Prendes --- .github/workflows/basic.yml | 4 +++- rustfmt.toml | 6 ++++++ scripts/cargo.sh | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 rustfmt.toml diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 477f7dc6..2ef251e0 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -44,7 +44,9 @@ jobs: - name: Setup Rust toolchain and cache uses: actions-rust-lang/setup-rust-toolchain@v1 with: - components: rustfmt, clippy + components: clippy + - name: Install nightly rustfmt + run: rustup toolchain install nightly --component rustfmt --profile minimal --no-self-update - name: typos-action uses: crate-ci/typos@v1.14.12 - name: Install just diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..83b03de8 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,6 @@ +newline_style = "Native" +unstable_features = true # Cargo fmt now needs to be called with `cargo +nightly fmt` +group_imports = "StdExternalCrate" # create three groups for std, external and local crates +# Merge imports from the same module +# See: https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#imports_granularity +imports_granularity = "Module" diff --git a/scripts/cargo.sh b/scripts/cargo.sh index 1e78bcfa..1f72db45 100755 --- a/scripts/cargo.sh +++ b/scripts/cargo.sh @@ -48,6 +48,9 @@ if [ "$1" == "fmt" ]; then # running cargo fmt fails when run through cross # also cargo fmt is platform independent CARGO="cargo" + + # Use nightly for `cargo fmt` as `rustfmt.toml` uses unstable features. + set -- "+nightly" "$@" fi if [ "$CARGO" == "cross" ]; then