Skip to content

Commit 49711eb

Browse files
committed
fix(lint-toml): improve file handling and whitespace robustness
Update the lint-toml script to handle file existence checks and improve whitespace handling: - Collect existing files into array before processing - Use array expansion for safer filename handling - Add proper quoting around filenames to handle spaces - Maintain same functionality while improving robustness This ensures the script works correctly with files containing spaces and avoids errors when files don't exist.
1 parent da812cf commit 49711eb

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

template/.config/copier/mise/tasks/lint-toml.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ function has() {
1010
}
1111

1212
function pretty-toml() {
13+
local files=()
14+
for file in "$@"; do
15+
if [[ -f $file ]]; then
16+
files+=("$file")
17+
fi
18+
done
1319
if has toml-sort; then
14-
toml-sort --in-place --all "$@"
15-
sed --expression='s/# :schema /#:schema /g' --in-place "$@"
20+
toml-sort --in-place --all "${files[@]}"
21+
sed --expression='s/# :schema /#:schema /g' --in-place "${files[@]}"
1622
fi
1723
if has tombi; then
18-
tombi format "$@"
24+
tombi format "${files[@]}"
1925
fi
2026
}
2127

22-
pretty-toml .ruff.toml pyproject.toml
28+
pretty-toml '.ruff.toml' 'pyproject.toml'
2329

2430
if has tombi; then
2531
tombi lint

0 commit comments

Comments
 (0)