Skip to content

Commit 9364a1f

Browse files
committed
[PLUTO-1431] fx order
1 parent 7bd2e3a commit 9364a1f

File tree

2 files changed

+317
-73
lines changed

2 files changed

+317
-73
lines changed

integration-tests/run.ps1

Lines changed: 129 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,95 @@ function Normalize-Config {
2323
param ([string]$file)
2424

2525
Write-Host "Normalizing config file: $file"
26-
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')
2726

28-
switch ($ext) {
29-
{ $_ -in @('yaml', 'yml') } {
30-
Normalize-YamlConfig $file
31-
}
32-
{ $_ -in @('mjs', 'js') } {
33-
Normalize-EslintConfig $file
34-
}
35-
'toml' {
36-
Normalize-TomlConfig $file
37-
}
38-
{ $_ -in @('rc', 'conf', 'ini') } {
39-
Normalize-RcConfig $file
40-
}
41-
'xml' {
42-
Normalize-XmlConfig $file
27+
# Check for specific files first, then fall back to extension
28+
if ($file -like "*languages-config.yaml") {
29+
Normalize-LanguagesConfig $file
30+
} else {
31+
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')
32+
33+
switch ($ext) {
34+
{ $_ -in @('yaml', 'yml') } {
35+
Normalize-YamlConfig $file
36+
}
37+
{ $_ -in @('mjs', 'js') } {
38+
Normalize-EslintConfig $file
39+
}
40+
'toml' {
41+
Normalize-TomlConfig $file
42+
}
43+
{ $_ -in @('rc', 'conf', 'ini') } {
44+
Normalize-RcConfig $file
45+
}
46+
'xml' {
47+
Normalize-XmlConfig $file
48+
}
49+
default {
50+
Get-Content $file | Sort-Object
51+
}
4352
}
44-
default {
45-
Get-Content $file | Sort-Object
53+
}
54+
}
55+
56+
# Normalize languages-config.yaml specifically
57+
function Normalize-LanguagesConfig {
58+
param([string]$file)
59+
60+
$content = Get-Content $file
61+
$inTools = $false
62+
$toolLines = @()
63+
$output = @()
64+
$currentTool = @()
65+
66+
foreach ($line in $content) {
67+
if ($line -match '^\s*tools:\s*$') {
68+
$output += $line
69+
$inTools = $true
70+
} elseif ($inTools -and $line -match '^\s*-\s*name:') {
71+
# Start of a new tool, save previous if exists
72+
if ($currentTool.Count -gt 0) {
73+
$toolName = ($currentTool[0] -replace '^\s*-\s*name:\s*', '').Trim()
74+
$toolLines += @{ Name = $toolName; Lines = $currentTool }
75+
$currentTool = @()
76+
}
77+
$currentTool += $line
78+
} elseif ($inTools -and $line -match '^\s*\w+:') {
79+
# Part of current tool
80+
$currentTool += $line
81+
} elseif ($inTools -and $line -match '^\s*$') {
82+
# Empty line, could be end of tools section
83+
if ($currentTool.Count -gt 0) {
84+
$toolName = ($currentTool[0] -replace '^\s*-\s*name:\s*', '').Trim()
85+
$toolLines += @{ Name = $toolName; Lines = $currentTool }
86+
$currentTool = @()
87+
}
88+
# Check if next non-empty line starts a new section
89+
$output += $line
90+
} else {
91+
# End of tools section or other content
92+
if ($currentTool.Count -gt 0) {
93+
$toolName = ($currentTool[0] -replace '^\s*-\s*name:\s*', '').Trim()
94+
$toolLines += @{ Name = $toolName; Lines = $currentTool }
95+
$currentTool = @()
96+
}
97+
$inTools = $false
98+
$output += $line
4699
}
47100
}
101+
102+
# Handle last tool if exists
103+
if ($currentTool.Count -gt 0) {
104+
$toolName = ($currentTool[0] -replace '^\s*-\s*name:\s*', '').Trim()
105+
$toolLines += @{ Name = $toolName; Lines = $currentTool }
106+
}
107+
108+
# Sort tools by name and add to output
109+
$sortedTools = $toolLines | Sort-Object Name
110+
foreach ($tool in $sortedTools) {
111+
$output += $tool.Lines
112+
}
113+
114+
$output
48115
}
49116

50117
# Normalize YAML configuration files
@@ -126,38 +193,71 @@ function Normalize-XmlConfig {
126193
param([string]$file)
127194

128195
$lines = Get-Content $file
129-
$rules = @()
196+
$ruleBlocks = @()
197+
$singleRules = @()
130198
$output = @()
131199
$endTag = $null
200+
$inRuleBlock = $false
132201
$inProps = $false
133202
$properties = @()
134203
$propsStart = $null
204+
$currentRuleBlock = @()
205+
$currentRuleRef = ""
135206

136207
foreach ($line in $lines) {
137208
$trimmed = $line.TrimStart()
138209

139-
if ($trimmed -match '^<properties>') {
210+
if ($trimmed -match '^<rule ref="([^"]+)">$') {
211+
# Start of a rule block with properties
212+
$inRuleBlock = $true
213+
$currentRuleRef = $matches[1]
214+
$currentRuleBlock = @($trimmed)
215+
} elseif ($trimmed -match '^<rule ref="[^"]+"/>$') {
216+
# Self-closing rule (no properties)
217+
$singleRules += $trimmed
218+
} elseif ($inRuleBlock -and $trimmed -match '^<properties>') {
140219
$inProps = $true
141220
$propsStart = $trimmed
142221
$properties = @()
143-
} elseif ($trimmed -match '^</properties>') {
222+
} elseif ($inRuleBlock -and $inProps -and $trimmed -match '^</properties>') {
144223
$inProps = $false
145-
# Add sorted properties block
146-
$output += $propsStart
147-
$output += ($properties | Sort-Object)
148-
$output += $trimmed
149-
} elseif ($inProps -and $trimmed -match '^<property') {
224+
# Add sorted properties to rule block
225+
$currentRuleBlock += $propsStart
226+
$currentRuleBlock += ($properties | Sort-Object)
227+
$currentRuleBlock += $trimmed
228+
} elseif ($inRuleBlock -and $inProps -and $trimmed -match '^<property') {
150229
$properties += $trimmed
151-
} elseif ($trimmed -match '^<rule ref=') {
152-
$rules += $trimmed
230+
} elseif ($inRuleBlock -and $trimmed -match '^</rule>') {
231+
# End of rule block
232+
$currentRuleBlock += $trimmed
233+
$ruleBlocks += @{
234+
Ref = $currentRuleRef
235+
Block = $currentRuleBlock
236+
}
237+
$inRuleBlock = $false
238+
$currentRuleBlock = @()
239+
$currentRuleRef = ""
240+
} elseif ($inRuleBlock) {
241+
# Part of current rule block
242+
$currentRuleBlock += $trimmed
153243
} elseif ($trimmed -match '^</ruleset>') {
154244
$endTag = $trimmed
155245
} else {
156246
$output += $trimmed
157247
}
158248
}
159249

160-
$output + ($rules | Sort-Object) + $endTag
250+
# Sort rule blocks by reference and add to output
251+
$sortedRuleBlocks = $ruleBlocks | Sort-Object Ref
252+
foreach ($ruleBlock in $sortedRuleBlocks) {
253+
$output += $ruleBlock.Block
254+
}
255+
256+
# Add sorted single rules
257+
$output += ($singleRules | Sort-Object)
258+
259+
# Add end tag
260+
$output + $endTag
161261
}
162262

163263

0 commit comments

Comments
 (0)