Skip to content

Commit e3c3b9c

Browse files
Comply with TOML string requirements
Drops string handling from pre-commit entirely. rustfmt --config option can't be used with the parameters 'as is' (string values as unquoted). Instead use rustfmt --config-path that takes the whole fmt.toml file. To be able to use --config-path requires the nightly toolchain to be added to the docker dev container as well. This change additionally drops the license-template-path formatting parameter as it is no longer supported by the rust toolchain. See github discussion: rust-lang/rustfmt#3352 Signed-off-by: Matthew Schlebusch <[email protected]>
1 parent 32028db commit e3c3b9c

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

pre-commit

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ for i in $(git diff --name-only --cached); do
2222
filename=$(basename -- "$i")
2323
extension="${filename##*.}"
2424
if [ "$extension" = "rs" ]; then
25-
# Read rustfmt config, replace '\n' with ','
26-
rustfmt_config="$(sed -z "s/\n/,/g;s/,$/\n/" ./tests/fmt.toml)"
2725
# We first do a check run, this will fail when it finds a non-matching license.
28-
rustfmt $i --check --config $rustfmt_config
29-
# Run `cargo fmt` for this file
30-
rustfmt $i --config $rustfmt_config
26+
rustfmt $i +nightly --check --config-path ./tests/fmt.toml
27+
28+
# Run `cargo fmt` for this source file using the fmt.toml config
29+
rustfmt $i +nightly --config-path ./tests/fmt.toml
3130
fi
3231
if [ "$extension" = "py" ]; then
3332
# Run `black` for this file

tests/fmt.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# This file can be used as a whole TOML file via rustfmt's --config-path option
2+
# The individual key-pairs can also used with the rustfmt --config option,
3+
# but requires removing the quotes to work
4+
15
comment_width=100
26
wrap_comments=true
37
format_code_in_doc_comments=true
48
format_strings=true
5-
license_template_path=./tests/license.txt
6-
imports_granularity=Module
9+
imports_granularity="Module"
710
normalize_comments=true
811
normalize_doc_attributes=true
9-
group_imports=StdExternalCrate
12+
group_imports="StdExternalCrate"

tests/integration_tests/style/test_rust.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ def test_rust_style():
1212
@type: style
1313
"""
1414

15-
# ../src/io_uring/src/bindings.rs
16-
config = open("fmt.toml", encoding="utf-8").read().replace("\n", ",")
1715
# Check that the output is empty.
18-
_, stdout, _ = utils.run_cmd(f"cargo fmt --all -- --check --config {config}")
16+
_, stdout, _ = utils.run_cmd("cargo fmt --all -- --check --config-path fmt.toml")
1917

2018
# rustfmt prepends `"Diff in"` to the reported output.
2119
assert "Diff in" not in stdout

tools/devctr/Dockerfile.aarch64

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ RUN cd "$TMP_POETRY_DIR" \
100100
RUN mkdir "$TMP_BUILD_DIR" \
101101
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN" \
102102
&& rustup target add aarch64-unknown-linux-musl \
103+
&& rustup install nightly \
104+
&& rustup install --profile minimal "stable" \
103105
&& rustup component add clippy \
104106
&& cd "$TMP_BUILD_DIR" \
105107
&& cargo install cargo-kcov \

tools/devctr/Dockerfile.x86_64

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ RUN mkdir "$TMP_BUILD_DIR" \
108108
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN" \
109109
&& rustup target add x86_64-unknown-linux-musl \
110110
&& rustup component add rustfmt clippy clippy-preview \
111+
&& rustup install nightly \
111112
&& rustup install --profile minimal "stable" \
112113
&& cd "$TMP_BUILD_DIR" \
113114
&& cargo install cargo-kcov \

0 commit comments

Comments
 (0)