@@ -28,21 +28,53 @@ normalize_config() {
2828 if command -v node > /dev/null 2>&1 ; then
2929 node -e "
3030 const fs = require('fs');
31- const content = fs.readFileSync('$file ', 'utf8');
31+ let content = fs.readFileSync('$file ', 'utf8');
3232
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(', ') + '}';
33+ // More sophisticated approach: find and sort the rules object specifically
34+ const sortRulesObject = (str) => {
35+ // Find the rules object
36+ const rulesMatch = str.match(/rules:\s*\{([^}]+(?:\{[^}]*\}[^}]*)*)\}/);
37+ if (rulesMatch) {
38+ const rulesContent = rulesMatch[1];
39+
40+ // Split on commas but be careful about nested objects
41+ const rules = [];
42+ let current = '';
43+ let depth = 0;
44+ let inString = false;
45+ let stringChar = '';
46+
47+ for (let i = 0; i < rulesContent.length; i++) {
48+ const char = rulesContent[i];
49+ current += char;
50+
51+ if (!inString && (char === '\" ' || char === \" '\" )) {
52+ inString = true;
53+ stringChar = char;
54+ } else if (inString && char === stringChar && rulesContent[i-1] !== '\\\\ ') {
55+ inString = false;
56+ } else if (!inString) {
57+ if (char === '{') depth++;
58+ else if (char === '}') depth--;
59+ else if (char === ',' && depth === 0) {
60+ rules.push(current.slice(0, -1).trim());
61+ current = '';
62+ }
63+ }
4064 }
41- return match;
42- });
65+ if (current.trim()) rules.push(current.trim());
66+
67+ // Sort the rules
68+ rules.sort();
69+
70+ // Reconstruct
71+ const sortedRules = 'rules: {\\ n' + rules.map(rule => ' ' + rule).join(',\\ n') + '\\ n }';
72+ return str.replace(/rules:\s*\{([^}]+(?:\{[^}]*\}[^}]*)*)\}/, sortedRules);
73+ }
74+ return str;
4375 };
4476
45- console.log(sortObjectProperties (content));
77+ console.log(sortRulesObject (content));
4678 "
4779 else
4880 # Fallback if Node.js is not available
0 commit comments