Conversation
|
I had essentially the same idea about a week ago. The main problem I see with our current approach is that we don't enforce consistent formatting for our TOML files, which leads to formatting noise. One thing which would be nice to solve in addition to what this PR currently does is key sorting, so we don't have to bother doing it manually. Taplo can do this with the Whichever option we go with, it should be something we're all comfortable running locally, ideally via the editor, since dealing with autoformatting which isn't available locally is a huge pain. This means that we should also integrate the TOML formatter into diff --git a/build_tools/style.fish b/build_tools/style.fish
index b8fd1f8a04..22dd4e1fa2 100755
--- a/build_tools/style.fish
+++ b/build_tools/style.fish
@@ -30,7 +30,8 @@
if not set -l -q _flag_force; and not set -l -q _flag_check
# Potential for false positives: Not all fish files are formatted, see the `fish_files`
# definition below.
- set -l relevant_uncommitted_changes (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//' | grep -E '.*\.(fish|py|rs)$')
+ set -l relevant_uncommitted_changes (git status --porcelain --short --untracked-files=all |
+ sed -e 's/^ *[^ ]* *//' | grep -E '.*\.(fish|py|rs|toml)$')
if set -q relevant_uncommitted_changes[1]
for changed_file in $relevant_uncommitted_changes
echo $changed_file
@@ -45,12 +46,14 @@
end
set fish_files $workspace_root/{benchmarks,build_tools,etc,share}/**.fish
set python_files $workspace_root
+ set toml_files $workspace_root/**.toml
else
# Format the files specified as arguments.
set -l files $argv
set fish_files (string match -r '^.*\.fish$' -- $files)
set python_files (string match -r '^.*\.py$' -- $files)
set rust_files (string match -r '^.*\.rs$' -- $files)
+ set toml_files (string match -r '^.*\.toml$' -- $files)
end
set -l red (set_color red)
@@ -121,3 +124,18 @@
end
end
end
+
+if set -q toml_files[1]
+ if not type -q taplo
+ echo
+ echo $yellow'Please install `taplo` to style TOML'$normal
+ exit 127
+ end
+ echo === Running "$green"taplo fmt"$normal"
+ if set -l -q _flag_check
+ taplo fmt --check $toml_files
+ or die "TOML files are not formatted correctly."
+ else
+ taplo fmt $toml_files
+ end
+endThen we also don't need to explicitly run the formatter in CI, installing it is enough since the |
|
if we don't want 4-space indent in TOML files, we'd also want to update |
No description provided.