@plumeria/eslint-plugin 7.5.2 → 7.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rules/sort-properties.js +42 -3
- package/oxlint.json +1 -0
- package/package.json +1 -1
|
@@ -42,6 +42,36 @@ function getPropertyIndex(property, isTopLevel) {
|
|
|
42
42
|
}
|
|
43
43
|
return lastGroupIndex * 1000 + maxPropIndex + 1;
|
|
44
44
|
}
|
|
45
|
+
function getLIS(arr) {
|
|
46
|
+
const n = arr.length;
|
|
47
|
+
if (n === 0)
|
|
48
|
+
return [];
|
|
49
|
+
const dp = new Array(n).fill(1);
|
|
50
|
+
const parent = new Array(n).fill(-1);
|
|
51
|
+
for (let i = 0; i < n; i++) {
|
|
52
|
+
for (let j = 0; j < i; j++) {
|
|
53
|
+
if (arr[j] < arr[i] && dp[j] + 1 > dp[i]) {
|
|
54
|
+
dp[i] = dp[j] + 1;
|
|
55
|
+
parent[i] = j;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let maxLen = 0;
|
|
60
|
+
let bestEndIdx = 0;
|
|
61
|
+
for (let i = 0; i < n; i++) {
|
|
62
|
+
if (dp[i] > maxLen) {
|
|
63
|
+
maxLen = dp[i];
|
|
64
|
+
bestEndIdx = i;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const result = [];
|
|
68
|
+
let curr = bestEndIdx;
|
|
69
|
+
while (curr !== -1) {
|
|
70
|
+
result.push(curr);
|
|
71
|
+
curr = parent[curr];
|
|
72
|
+
}
|
|
73
|
+
return result.reverse();
|
|
74
|
+
}
|
|
45
75
|
exports.sortProperties = {
|
|
46
76
|
meta: {
|
|
47
77
|
type: 'suggestion',
|
|
@@ -87,15 +117,24 @@ exports.sortProperties = {
|
|
|
87
117
|
});
|
|
88
118
|
})
|
|
89
119
|
.flat();
|
|
90
|
-
const
|
|
91
|
-
|
|
120
|
+
const propertyToIndexInSorted = new Map();
|
|
121
|
+
sorted.forEach((prop, index) => {
|
|
122
|
+
propertyToIndexInSorted.set(prop, index);
|
|
123
|
+
});
|
|
124
|
+
const targetPositions = properties.map((prop) => propertyToIndexInSorted.get(prop));
|
|
125
|
+
const lisIndices = new Set(getLIS(targetPositions));
|
|
126
|
+
const misorderedIndices = properties
|
|
127
|
+
.map((_, i) => i)
|
|
128
|
+
.filter((i) => !lisIndices.has(i));
|
|
129
|
+
if (misorderedIndices.length === 0)
|
|
92
130
|
return;
|
|
93
131
|
const match = sourceCode.getText(node).match(/^{\s*\n(\s*)/);
|
|
94
132
|
const indent = match ? match[1] : '';
|
|
95
133
|
const lineEnding = match ? '\n' : ' ';
|
|
96
134
|
const closingIndentMatch = sourceCode.getText(node).match(/\n(\s*)}$/);
|
|
97
135
|
const closingIndent = closingIndentMatch ? closingIndentMatch[1] : '';
|
|
98
|
-
|
|
136
|
+
misorderedIndices.forEach((i) => {
|
|
137
|
+
const prop = properties[i];
|
|
99
138
|
context.report({
|
|
100
139
|
node: prop,
|
|
101
140
|
messageId: 'sortProperties',
|
package/oxlint.json
CHANGED