@plumeria/eslint-plugin 18.2.10 → 18.2.11
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/README.md +6 -0
- package/dist/rules/no-order-dependent-overlap.js +67 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -107,6 +107,12 @@ physical name, and two shorthands that cross without either containing the
|
|
|
107
107
|
other. A shorthand and its longhand are ranked by specificity and never
|
|
108
108
|
reported.
|
|
109
109
|
|
|
110
|
+
It also reports two conditions in one style where one provably matches a subset
|
|
111
|
+
of the other — `(min-width: 900px)` inside `(min-width: 600px)`, or two queries
|
|
112
|
+
naming the same container — and the narrower one is written first. The optimizer
|
|
113
|
+
places the narrower one last whatever the source says, so the declarations read
|
|
114
|
+
the wrong way round. The swap is offered as a suggestion rather than a fix.
|
|
115
|
+
|
|
110
116
|
A pair of spellings is one property in a horizontal writing mode and two
|
|
111
117
|
properties in a vertical one, which is per element and cannot be read from the
|
|
112
118
|
source. The rule reads them as one property; disable the line where an element
|
|
@@ -58,7 +58,9 @@ exports.noOrderDependentOverlap = {
|
|
|
58
58
|
messages: {
|
|
59
59
|
alias: "'{{ first }}' and '{{ second }}' are the same property under two names, so neither outranks the other. The one written last wins.",
|
|
60
60
|
crossing: "'{{ first }}' and '{{ second }}' overlap, but neither property outranks the other. The result depends on the order they are written.",
|
|
61
|
+
condition: "'{{ narrow }}' matches only where '{{ broad }}' also matches, so it is the more specific of the two, and both set '{{ property }}'. Written first, it reads as though the broader one wins, which is the opposite of what the stylesheet does.",
|
|
61
62
|
keep: "Keep '{{ keep }}'",
|
|
63
|
+
swap: "Write '{{ narrow }}' after '{{ broad }}'",
|
|
62
64
|
},
|
|
63
65
|
schema: [],
|
|
64
66
|
},
|
|
@@ -120,6 +122,33 @@ exports.noOrderDependentOverlap = {
|
|
|
120
122
|
}
|
|
121
123
|
},
|
|
122
124
|
};
|
|
125
|
+
function keyNameOf(prop) {
|
|
126
|
+
if (!prop.computed) {
|
|
127
|
+
return prop.key.type === 'Identifier'
|
|
128
|
+
? prop.key.name
|
|
129
|
+
: String(prop.key.value);
|
|
130
|
+
}
|
|
131
|
+
return prop.key.type === 'Literal' && typeof prop.key.value === 'string'
|
|
132
|
+
? prop.key.value
|
|
133
|
+
: '';
|
|
134
|
+
}
|
|
135
|
+
function declaredNames(node) {
|
|
136
|
+
const names = new Set();
|
|
137
|
+
node.properties.forEach((prop) => {
|
|
138
|
+
if (prop.type !== 'Property' || prop.value.type === 'ObjectExpression')
|
|
139
|
+
return;
|
|
140
|
+
const name = keyNameOf(prop);
|
|
141
|
+
if (name && !name.startsWith('--'))
|
|
142
|
+
names.add(name);
|
|
143
|
+
});
|
|
144
|
+
return names;
|
|
145
|
+
}
|
|
146
|
+
function swapProperties(fixer, first, second) {
|
|
147
|
+
return [
|
|
148
|
+
fixer.replaceText(first, sourceCode.getText(second)),
|
|
149
|
+
fixer.replaceText(second, sourceCode.getText(first)),
|
|
150
|
+
];
|
|
151
|
+
}
|
|
123
152
|
function removeProperty(fixer, prop) {
|
|
124
153
|
const after = sourceCode.getTokenAfter(prop);
|
|
125
154
|
if (after && after.value === ',') {
|
|
@@ -132,24 +161,24 @@ exports.noOrderDependentOverlap = {
|
|
|
132
161
|
}
|
|
133
162
|
function checkStyleObject(node) {
|
|
134
163
|
const declarations = [];
|
|
164
|
+
const conditions = [];
|
|
135
165
|
node.properties.forEach((prop) => {
|
|
136
166
|
if (prop.type !== 'Property')
|
|
137
167
|
return;
|
|
138
168
|
if (prop.value.type === 'ObjectExpression') {
|
|
169
|
+
const condition = keyNameOf(prop);
|
|
170
|
+
if (condition.startsWith('@media') ||
|
|
171
|
+
condition.startsWith('@container')) {
|
|
172
|
+
conditions.push({
|
|
173
|
+
prop,
|
|
174
|
+
name: condition,
|
|
175
|
+
sets: declaredNames(prop.value),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
139
178
|
checkStyleObject(prop.value);
|
|
140
179
|
return;
|
|
141
180
|
}
|
|
142
|
-
|
|
143
|
-
if (!prop.computed) {
|
|
144
|
-
name =
|
|
145
|
-
prop.key.type === 'Identifier'
|
|
146
|
-
? prop.key.name
|
|
147
|
-
: String(prop.key.value);
|
|
148
|
-
}
|
|
149
|
-
else if (prop.key.type === 'Literal' &&
|
|
150
|
-
typeof prop.key.value === 'string') {
|
|
151
|
-
name = prop.key.value;
|
|
152
|
-
}
|
|
181
|
+
const name = keyNameOf(prop);
|
|
153
182
|
if (!name ||
|
|
154
183
|
name.startsWith(':') ||
|
|
155
184
|
name.startsWith('[') ||
|
|
@@ -159,6 +188,33 @@ exports.noOrderDependentOverlap = {
|
|
|
159
188
|
}
|
|
160
189
|
declarations.push({ prop, name, kebab: (0, logicalPhysical_1.toKebabCase)(name) });
|
|
161
190
|
});
|
|
191
|
+
for (let i = 0; i < conditions.length; i++) {
|
|
192
|
+
for (let j = i + 1; j < conditions.length; j++) {
|
|
193
|
+
const first = conditions[i];
|
|
194
|
+
const second = conditions[j];
|
|
195
|
+
if (!(0, zss_engine_1.impliesCondition)(first.name, second.name))
|
|
196
|
+
continue;
|
|
197
|
+
const shared = [...first.sets].filter((name) => second.sets.has(name));
|
|
198
|
+
if (shared.length === 0)
|
|
199
|
+
continue;
|
|
200
|
+
context.report({
|
|
201
|
+
node: first.prop.key,
|
|
202
|
+
messageId: 'condition',
|
|
203
|
+
data: {
|
|
204
|
+
narrow: first.name,
|
|
205
|
+
broad: second.name,
|
|
206
|
+
property: shared[0],
|
|
207
|
+
},
|
|
208
|
+
suggest: [
|
|
209
|
+
{
|
|
210
|
+
messageId: 'swap',
|
|
211
|
+
data: { narrow: first.name, broad: second.name },
|
|
212
|
+
fix: (fixer) => swapProperties(fixer, first.prop, second.prop),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
162
218
|
for (let i = 0; i < declarations.length; i++) {
|
|
163
219
|
for (let j = i + 1; j < declarations.length; j++) {
|
|
164
220
|
const first = declarations[i];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/eslint-plugin",
|
|
3
|
-
"version": "18.2.
|
|
3
|
+
"version": "18.2.11",
|
|
4
4
|
"description": "Plumeria ESLint plugin",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@typescript-eslint/utils": "^8.60.0",
|
|
56
56
|
"known-css-properties": "^0.37.0",
|
|
57
|
-
"zss-engine": "2.
|
|
57
|
+
"zss-engine": "2.5.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "rimraf dist && pnpm cjs",
|