Skip to content

Commit

Permalink
Comply with TOML string requirements
Browse files Browse the repository at this point in the history
Adds string handling back into pre-commit to drop quotes for
rustfmt --config option to be able to use the string values
as unquoted.

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]>
  • Loading branch information
mattschlebusch committed Aug 19, 2022
1 parent e81013c commit 166b6e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@ for i in $(git diff --name-only --cached); do
if [ "$extension" = "rs" ]; then
# Read rustfmt config, replace '\n' with ','
rustfmt_config="$(sed -z "s/\n/,/g;s/,$/\n/" ./tests/fmt.toml)"

# TOML file standard requires string to be quoted.
# For the fmt.toml parameters to be passed manually to --config,
# the quotes need to be dropped manually.
# Using the TOML format for the format rules (fmt.toml) is still useful
# in case it is used with the --config-path switch which parses TOML.
rustfmt_config=$(echo "$rustfmt_config" | tr -d '"')

# We first do a check run, this will fail when it finds a non-matching license.
rustfmt $i --check --config $rustfmt_config

# Run `cargo fmt` for this file
rustfmt $i --config $rustfmt_config
fi
Expand Down
9 changes: 6 additions & 3 deletions tests/fmt.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# This file can be used as a whole TOML file via rustfmt's --config-path option
# The individual key-pairs are also used by the pre-commit script
# via the rustfmt --config option.

comment_width=100
wrap_comments=true
format_code_in_doc_comments=true
format_strings=true
license_template_path=./tests/license.txt
imports_granularity=Module
imports_granularity="Module"
normalize_comments=true
normalize_doc_attributes=true
group_imports=StdExternalCrate
group_imports="StdExternalCrate"

0 comments on commit 166b6e9

Please sign in to comment.