Skip to content

Commit 7bd2e3a

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

File tree

6 files changed

+134
-45
lines changed

6 files changed

+134
-45
lines changed

integration-tests/init-without-token/expected/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ tools:
1212
1313
1414
15-
15+

integration-tests/init-without-token/expected/tools-configs/eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default [
99
"no-class-assign": ["error"],
1010
"no-compare-neg-zero": ["error"],
1111
"no-cond-assign": ["error", "except-parens"],
12-
"no-const-assign": ["error"],
1312
"no-constant-condition": ["error", {"checkLoops": true}],
13+
"no-const-assign": ["error"],
1414
"no-control-regex": ["error"],
1515
"no-debugger": ["error"],
1616
"no-delete-var": ["error"],
@@ -31,7 +31,7 @@ export default [
3131
"no-import-assign": ["error"],
3232
"no-inner-declarations": ["error", "functions"],
3333
"no-invalid-regexp": ["error"],
34-
"no-irregular-whitespace": ["error", {"skipStrings": true, "skipJSXText": false, "skipRegExps": false, "skipComments": false, "skipTemplates": false}],
34+
"no-irregular-whitespace": ["error", {"skipComments": false, "skipJSXText": false, "skipRegExps": false, "skipStrings": true, "skipTemplates": false}],
3535
"no-loss-of-precision": ["error"],
3636
"no-misleading-character-class": ["error"],
3737
"no-mixed-spaces-and-tabs": ["error"],
@@ -60,7 +60,7 @@ export default [
6060
"no-useless-escape": ["error"],
6161
"no-with": ["error"],
6262
"require-yield": ["error"],
63-
"use-isnan": ["error", {"enforceForSwitchCase": true, "enforceForIndexOf": false}],
63+
"use-isnan": ["error", {"enforceForIndexOf": false, "enforceForSwitchCase": true}],
6464
"valid-typeof": ["error", {"requireStringLiterals": false}],
6565
}
6666
}

integration-tests/init-without-token/expected/tools-configs/lizard.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ patterns:
4747
severityLevel: Warning
4848
threshold: 8
4949
timeToFix: 5
50-
title: Enforce Medium Parameter Count Limit
50+
title: Enforce Medium Parameter Count Limit

integration-tests/init-without-token/expected/tools-configs/ruleset.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<ruleset name="Codacy PMD Ruleset"
3-
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
66
<description>Codacy PMD Ruleset</description>
77
<rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts"/>
88
<rule ref="category/apex/design.xml/ExcessiveClassLength"/>
@@ -13,8 +13,8 @@
1313
<rule ref="category/apex/security.xml/ApexDangerousMethods"/>
1414
<rule ref="category/apex/security.xml/ApexInsecureEndpoint"/>
1515
<rule ref="category/apex/security.xml/ApexOpenRedirect"/>
16-
<rule ref="category/apex/security.xml/ApexSOQLInjection"/>
1716
<rule ref="category/apex/security.xml/ApexSharingViolations"/>
17+
<rule ref="category/apex/security.xml/ApexSOQLInjection"/>
1818
<rule ref="category/apex/security.xml/ApexSuggestUsingNamedCred"/>
1919
<rule ref="category/apex/security.xml/ApexXSSFromEscapeFalse"/>
2020
<rule ref="category/apex/security.xml/ApexXSSFromURLParam"/>
@@ -23,12 +23,12 @@
2323
<rule ref="category/ecmascript/bestpractices.xml/UseBaseWithParseInt"/>
2424
<rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand">
2525
<properties>
26-
<property name="allowWhile" value="false"/>
27-
<property name="allowIf" value="false"/>
28-
<property name="allowTernaryResults" value="false"/>
29-
<property name="allowTernary" value="false"/>
3026
<property name="allowFor" value="false"/>
27+
<property name="allowIf" value="false"/>
3128
<property name="allowIncrementDecrement" value="false"/>
29+
<property name="allowTernary" value="false"/>
30+
<property name="allowTernaryResults" value="false"/>
31+
<property name="allowWhile" value="false"/>
3232
</properties>
3333
</rule>
3434
<rule ref="category/ecmascript/codestyle.xml/UnnecessaryBlock"/>
@@ -49,13 +49,13 @@
4949
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
5050
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
5151
<properties>
52-
<property name="testClassPattern" value="^Test.*$|^[A-Z][a-zA-Z0-9]*Test(s|Case)?$"/>
5352
<property name="abstractClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
54-
<property name="classPattern" value="[A-Z][a-zA-Z0-9]*"/>
55-
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
5653
<property name="annotationPattern" value="[A-Z][a-zA-Z0-9]*"/>
54+
<property name="classPattern" value="[A-Z][a-zA-Z0-9]*"/>
5755
<property name="enumPattern" value="[A-Z][a-zA-Z0-9]*"/>
5856
<property name="interfacePattern" value="[A-Z][a-zA-Z0-9]*"/>
57+
<property name="testClassPattern" value="^Test.*$|^[A-Z][a-zA-Z0-9]*Test(s|Case)?$"/>
58+
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
5959
</properties>
6060
</rule>
6161
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
@@ -64,11 +64,11 @@
6464
<rule ref="category/java/codestyle.xml/MethodNamingConventions">
6565
<properties>
6666
<property name="junit3TestPattern" value="test[A-Z0-9][a-zA-Z0-9]*"/>
67+
<property name="junit4TestPattern" value="[a-z][a-zA-Z0-9]*"/>
6768
<property name="junit5TestPattern" value="[a-z][a-zA-Z0-9]*"/>
68-
<property name="staticPattern" value="[a-z][a-zA-Z0-9]*"/>
6969
<property name="methodPattern" value="[a-z][a-zA-Z0-9]*"/>
70-
<property name="junit4TestPattern" value="[a-z][a-zA-Z0-9]*"/>
7170
<property name="nativePattern" value="[a-z][a-zA-Z0-9]*"/>
71+
<property name="staticPattern" value="[a-z][a-zA-Z0-9]*"/>
7272
</properties>
7373
</rule>
7474
<rule ref="category/java/codestyle.xml/NoPackage"/>
@@ -104,9 +104,9 @@
104104
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
105105
<rule ref="category/java/errorprone.xml/EmptyFinalizer"/>
106106
<rule ref="category/java/errorprone.xml/EqualsNull"/>
107+
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
107108
<rule ref="category/java/errorprone.xml/JUnitSpelling"/>
108109
<rule ref="category/java/errorprone.xml/JUnitStaticSuite"/>
109-
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
110110
<rule ref="category/java/errorprone.xml/MethodWithSameNameAsEnclosingClass"/>
111111
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
112112
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass">
@@ -152,8 +152,8 @@
152152
<property name="maxmethods" value="1"/>
153153
</properties>
154154
</rule>
155-
<rule ref="category/plsql/errorprone.xml/TO_DATEWithoutDateFormat"/>
156155
<rule ref="category/plsql/errorprone.xml/TO_DATE_TO_CHAR"/>
156+
<rule ref="category/plsql/errorprone.xml/TO_DATEWithoutDateFormat"/>
157157
<rule ref="category/plsql/errorprone.xml/TO_TIMESTAMPWithoutDateFormat"/>
158158
<rule ref="category/pom/errorprone.xml/InvalidDependencyTypes">
159159
<properties>

integration-tests/run.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Normalize-EslintConfig {
7070
$output += $line
7171
$inRules = $true
7272
} elseif ($inRules -and $line -match '^\s*\}') {
73-
# Sort collected rule lines and add them
73+
# Sort collected rule lines (since expected file already has properties sorted)
7474
$output += ($ruleLines | Sort-Object)
7575
$ruleLines = @()
7676
$inRules = $false
@@ -129,10 +129,26 @@ function Normalize-XmlConfig {
129129
$rules = @()
130130
$output = @()
131131
$endTag = $null
132+
$inProps = $false
133+
$properties = @()
134+
$propsStart = $null
132135

133136
foreach ($line in $lines) {
134137
$trimmed = $line.TrimStart()
135-
if ($trimmed -match '^<rule ref=') {
138+
139+
if ($trimmed -match '^<properties>') {
140+
$inProps = $true
141+
$propsStart = $trimmed
142+
$properties = @()
143+
} elseif ($trimmed -match '^</properties>') {
144+
$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') {
150+
$properties += $trimmed
151+
} elseif ($trimmed -match '^<rule ref=') {
136152
$rules += $trimmed
137153
} elseif ($trimmed -match '^</ruleset>') {
138154
$endTag = $trimmed

integration-tests/run.sh

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ normalize_eslint_config() {
6464
next
6565
}
6666
inRules && /^\s*\}/ {
67-
# Sort collected rules and print them
68-
n = asorti(rules, sortedIndices)
69-
for (i = 1; i <= n; i++) {
70-
print rules[sortedIndices[i]]
67+
# Print collected rules in sorted order using pipe to sort
68+
for (rule in rules) {
69+
print rules[rule] | "sort"
7170
}
71+
close("sort")
7272
delete rules
7373
inRules = 0
7474
print
@@ -90,24 +90,47 @@ normalize_toml_config() {
9090
awk -F'=' '
9191
/^[^#].*=.*\[.*\]/ {
9292
# Handle TOML arrays like: rules = ["a", "b", "c"]
93-
match($2, /\[(.*)\]/, arr)
94-
if (arr[1]) {
95-
split(arr[1], values, /,\s*/)
96-
# Sort values
97-
n = asort(values)
98-
printf "%s=[", $1
99-
for (i=1; i<=n; i++) {
100-
if (i>1) printf ", "
101-
printf "%s", values[i]
93+
# Extract array content using substr and index instead of match with array
94+
start = index($2, "[")
95+
end = index($2, "]")
96+
if (start > 0 && end > start) {
97+
array_content = substr($2, start+1, end-start-1)
98+
if (array_content) {
99+
# Split and sort values
100+
n = split(array_content, values, /,\s*/)
101+
# Sort using a simple bubble sort since asort is not available
102+
for (i = 1; i <= n; i++) {
103+
for (j = i+1; j <= n; j++) {
104+
if (values[i] > values[j]) {
105+
temp = values[i]
106+
values[i] = values[j]
107+
values[j] = temp
108+
}
109+
}
110+
}
111+
printf "%s=[", $1
112+
for (i=1; i<=n; i++) {
113+
if (i>1) printf ", "
114+
printf "%s", values[i]
115+
}
116+
print "]"
117+
next
102118
}
103-
print "]"
104-
next
105119
}
106120
}
107121
/^[^#].*=.*,/ {
108122
# Handle simple comma-separated values
109-
split($2, values, ",")
110-
n = asort(values)
123+
n = split($2, values, ",")
124+
# Sort using bubble sort
125+
for (i = 1; i <= n; i++) {
126+
for (j = i+1; j <= n; j++) {
127+
if (values[i] > values[j]) {
128+
temp = values[i]
129+
values[i] = values[j]
130+
values[j] = temp
131+
}
132+
}
133+
}
111134
printf "%s=", $1
112135
for (i=1; i<=n; i++) {
113136
if (i>1) printf ","
@@ -126,8 +149,17 @@ normalize_rc_config() {
126149
# Handle key-value pairs with comma-separated values
127150
awk -F'=' '
128151
/^[^#].*=.*,/ {
129-
split($2, values, ",")
130-
n = asort(values)
152+
n = split($2, values, ",")
153+
# Sort using bubble sort
154+
for (i = 1; i <= n; i++) {
155+
for (j = i+1; j <= n; j++) {
156+
if (values[i] > values[j]) {
157+
temp = values[i]
158+
values[i] = values[j]
159+
values[j] = temp
160+
}
161+
}
162+
}
131163
printf "%s=", $1
132164
for (i=1; i<=n; i++) {
133165
if (i>1) printf ","
@@ -143,9 +175,41 @@ normalize_rc_config() {
143175
# Normalize XML configuration files
144176
normalize_xml_config() {
145177
local file=$1
146-
# Sort rule references while preserving XML structure
178+
# Sort rule references and properties within properties blocks
147179
awk '
148-
BEGIN { n = 0; end = ""; }
180+
BEGIN {
181+
n = 0;
182+
end = "";
183+
in_props = 0;
184+
props_count = 0;
185+
}
186+
/^ *<properties>/ {
187+
in_props = 1;
188+
props_start = $0;
189+
props_count = 0;
190+
next
191+
}
192+
/^ *<\/properties>/ {
193+
in_props = 0;
194+
# Sort and print collected properties
195+
print props_start;
196+
for (i = 1; i <= props_count; i++) {
197+
for (j = i+1; j <= props_count; j++) {
198+
if (props[i] > props[j]) {
199+
temp = props[i]
200+
props[i] = props[j]
201+
props[j] = temp
202+
}
203+
}
204+
}
205+
for (i = 1; i <= props_count; i++) print props[i];
206+
print $0;
207+
next
208+
}
209+
in_props && /^ *<property/ {
210+
props[++props_count] = $0;
211+
next
212+
}
149213
/^ *<rule ref=/ {
150214
rules[++n] = $0;
151215
next
@@ -160,8 +224,17 @@ normalize_xml_config() {
160224
}
161225
END {
162226
if (n > 0) {
163-
n = asort(rules, sorted_rules)
164-
for (i = 1; i <= n; i++) print sorted_rules[i]
227+
# Sort rule references using bubble sort
228+
for (i = 1; i <= n; i++) {
229+
for (j = i+1; j <= n; j++) {
230+
if (rules[i] > rules[j]) {
231+
temp = rules[i]
232+
rules[i] = rules[j]
233+
rules[j] = temp
234+
}
235+
}
236+
}
237+
for (i = 1; i <= n; i++) print rules[i];
165238
}
166239
if (end) print end
167240
}

0 commit comments

Comments
 (0)