Skip to content

Commit 920ddea

Browse files
committed
fix(yamlfmt): check all local config file variants
yamlfmt script missed some valid file names when checking current dir for local config files This adds all possible files names mentioned in the docs: https://github.com/google/yamlfmt/blob/main/docs/config-file.md Signed-off-by: Asser Hakala <extern.asser.hakala@digg.se>
1 parent 729937e commit 920ddea

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

linters/yaml.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@ find_yaml_files() {
2323
2>/dev/null
2424
}
2525

26+
has_local_config() {
27+
local config_files=(
28+
".yamlfmt"
29+
".yamlfmt.yml"
30+
".yamlfmt.yaml"
31+
"yamlfmt.yml"
32+
"yamlfmt.yaml"
33+
)
34+
35+
for file in "${config_files[@]}"; do
36+
[[ -f "$file" ]] && return 0
37+
done
38+
39+
return 1
40+
}
41+
2642
get_config_flag() {
27-
# If project has its own config, use default behavior; otherwise use our default
28-
if [[ ! -f ".yamlfmt" && ! -f "yamlfmt.yml" && ! -f "yamlfmt.yaml" && -f "${DEFAULT_CONFIG}" ]]; then
43+
# If project has its own config, do nothing
44+
if has_local_config; then
45+
return 0
46+
fi
47+
48+
# Otherwise, use default config if it exists
49+
if [[ -f "${DEFAULT_CONFIG}" ]]; then
2950
printf "%s" "-conf ${DEFAULT_CONFIG}"
3051
fi
3152
}

0 commit comments

Comments
 (0)