File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,26 @@ function Normalize-Config {
2020 $ext = [System.IO.Path ]::GetExtension($file ).TrimStart(' .' )
2121
2222 switch ($ext ) {
23- { $_ -in @ (' yaml' , ' yml' ) } { yq e ' .' $file | Sort-Object }
23+ { $_ -in @ (' yaml' , ' yml' ) } {
24+ # For YAML files, preserve the structure and sort within each section
25+ $content = Get-Content $file - Raw
26+ $runtimes = ($content | Select-String - Pattern " runtimes:[\s\S]*?tools:" - AllMatches).Matches.Value
27+ $tools = ($content | Select-String - Pattern " tools:[\s\S]*?$" - AllMatches).Matches.Value
28+
29+ # Sort runtimes section
30+ $runtimes = $runtimes -replace " runtimes:" , " " -replace " tools:" , " "
31+ $runtimes = $runtimes -split " `n " | Where-Object { $_ -match " ^\s*-\s*" } | Sort-Object
32+
33+ # Sort tools section
34+ $tools = $tools -replace " tools:" , " "
35+ $tools = $tools -split " `n " | Where-Object { $_ -match " ^\s*-\s*" } | Sort-Object
36+
37+ # Reconstruct the YAML
38+ " runtimes:"
39+ $runtimes
40+ " tools:"
41+ $tools
42+ }
2443 { $_ -in @ (' rc' , ' conf' , ' ini' , ' xml' ) } {
2544 Get-Content $file | ForEach-Object {
2645 if ($_ -match ' ^[^#].*=.*,' ) {
You can’t perform that action at this time.
0 commit comments