Skip to content

Commit f26bf99

Browse files
committed
[PLUTO-1431] normalize toml files
1 parent faaf3dd commit f26bf99

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

integration-tests/run.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,18 @@ function Normalize-Config {
9696
}
9797
$output
9898
}
99-
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
99+
{ $_ -in @('rc', 'conf', 'ini', 'toml', 'xml') } {
100100
Get-Content $file | ForEach-Object {
101-
if ($_ -match '^[^#].*=.*,') {
101+
if ($_ -match '^[^#].*=.*\[.*\]') {
102+
# Handle TOML arrays like: rules = ["a", "b", "c"]
103+
$parts = $_ -split '='
104+
if ($parts[1] -match '\[(.*)\]') {
105+
$arrayContent = $matches[1]
106+
$values = $arrayContent -split ',\s*' | Sort-Object
107+
"$($parts[0])=[$($values -join ', ')]"
108+
} else { $_ }
109+
} elseif ($_ -match '^[^#].*=.*,') {
110+
# Handle simple comma-separated values
102111
$parts = $_ -split '='
103112
$values = $parts[1] -split ',' | Sort-Object
104113
"$($parts[0])=$($values -join ',')"

integration-tests/run.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,35 @@ normalize_config() {
5050
{ print }
5151
' "$file"
5252
;;
53-
rc|conf|ini)
54-
# For other config files, sort values after '=' and keep other lines
53+
rc|conf|ini|toml)
54+
# For config files, sort values after '=' and handle TOML arrays
5555
awk -F'=' '
56+
/^[^#].*=.*\[.*\]/ {
57+
# Handle TOML arrays like: rules = ["a", "b", "c"]
58+
match($2, /\[(.*)\]/, arr)
59+
if (arr[1]) {
60+
split(arr[1], values, /,\s*/)
61+
# Sort values using a simple bubble sort
62+
for (i=1; i<=length(values); i++) {
63+
for (j=i+1; j<=length(values); j++) {
64+
if (values[i] > values[j]) {
65+
temp = values[i]
66+
values[i] = values[j]
67+
values[j] = temp
68+
}
69+
}
70+
}
71+
printf "%s=[", $1
72+
for (i=1; i<=length(values); i++) {
73+
if (i>1) printf ", "
74+
printf "%s", values[i]
75+
}
76+
print "]"
77+
next
78+
}
79+
}
5680
/^[^#].*=.*,/ {
81+
# Handle simple comma-separated values
5782
split($2, values, ",")
5883
# Sort values using a simple bubble sort
5984
for (i=1; i<=length(values); i++) {

0 commit comments

Comments
 (0)