Skip to content

Commit f3da737

Browse files
committed
[PLUTO-1431] sort eslint rules
1 parent df7ec4d commit f3da737

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

integration-tests/run.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ function Normalize-Config {
7070

7171
$output
7272
}
73+
{ $_ -in @('mjs', 'js') } {
74+
# For JavaScript config files (like ESLint), use Node.js to parse and sort JSON objects
75+
if (Get-Command node -ErrorAction SilentlyContinue) {
76+
$tempScript = @"
77+
const fs = require('fs');
78+
const content = fs.readFileSync('$file', 'utf8');
79+
80+
// Simple approach: sort object properties in JSON-like structures
81+
const sortObjectProperties = (str) => {
82+
return str.replace(/\{[^{}]*\}/g, (match) => {
83+
if (match.includes(':')) {
84+
// Extract properties and sort them
85+
const props = match.slice(1, -1).split(',').map(p => p.trim()).sort();
86+
return '{' + props.join(', ') + '}';
87+
}
88+
return match;
89+
});
90+
};
91+
92+
console.log(sortObjectProperties(content));
93+
"@
94+
$tempScript | node
95+
} else {
96+
# Fallback if Node.js is not available
97+
Get-Content $file
98+
}
99+
}
73100
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
74101
Get-Content $file | ForEach-Object {
75102
if ($_ -match '^[^#].*=.*,') {

integration-tests/run.sh

100644100755
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ normalize_config() {
2323
# For YAML files, use yq to sort
2424
yq e '.' "$file" | sort
2525
;;
26+
mjs|js)
27+
# For JavaScript config files (like ESLint), use Node.js to parse and sort JSON objects
28+
if command -v node >/dev/null 2>&1; then
29+
node -e "
30+
const fs = require('fs');
31+
const content = fs.readFileSync('$file', 'utf8');
32+
33+
// Simple approach: sort object properties in JSON-like structures
34+
const sortObjectProperties = (str) => {
35+
return str.replace(/\{[^{}]*\}/g, (match) => {
36+
if (match.includes(':')) {
37+
// Extract properties and sort them
38+
const props = match.slice(1, -1).split(',').map(p => p.trim()).sort();
39+
return '{' + props.join(', ') + '}';
40+
}
41+
return match;
42+
});
43+
};
44+
45+
console.log(sortObjectProperties(content));
46+
"
47+
else
48+
# Fallback if Node.js is not available
49+
cat "$file"
50+
fi
51+
;;
2652
rc|conf|ini)
2753
# For other config files, sort values after '=' and keep other lines
2854
awk -F'=' '

0 commit comments

Comments
 (0)