@mrhenry/stylelint-mrhenry-nesting 3.1.0 → 3.1.2
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/index.mjs +56 -45
- package/package.json +5 -5
package/index.mjs
CHANGED
|
@@ -185,51 +185,65 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
let nestingCounter = 0;
|
|
188
|
-
{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
});
|
|
192
|
-
}
|
|
188
|
+
selectorAST.walkNesting(() => {
|
|
189
|
+
nestingCounter++;
|
|
190
|
+
});
|
|
193
191
|
|
|
194
192
|
// .foo { .bar & {} }
|
|
195
193
|
if (
|
|
196
|
-
context.fix &&
|
|
197
194
|
nestingCounter === 1 &&
|
|
198
195
|
selectorAST.nodes[selectorAST.nodes.length - 1]?.type === 'nesting' &&
|
|
199
196
|
selectorAST.nodes[selectorAST.nodes.length - 2]?.type === 'combinator'
|
|
200
197
|
) {
|
|
201
|
-
|
|
198
|
+
stylelint.utils.report({
|
|
199
|
+
message: messages.rejectedMustStartWithAmpersand(),
|
|
200
|
+
node: rule,
|
|
201
|
+
index: 0,
|
|
202
|
+
endIndex: rule.selector.length,
|
|
203
|
+
result: postcssResult,
|
|
204
|
+
ruleName,
|
|
205
|
+
fix: () => {
|
|
206
|
+
fixSelector_AncestorPattern(rule, selectorsAST, selectorAST);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
202
210
|
continue;
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
// .foo { :focus& {} }
|
|
206
214
|
if (
|
|
207
|
-
context.fix &&
|
|
208
215
|
selectorAST.nodes.length === 2 &&
|
|
209
216
|
selectorAST.nodes[0]?.type === 'pseudo' &&
|
|
210
217
|
selectorParser.isPseudoClass(selectorAST.nodes[0]) &&
|
|
211
218
|
selectorAST.nodes[1]?.type === 'nesting'
|
|
212
219
|
) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
stylelint.utils.report({
|
|
221
|
+
message: messages.rejectedMustStartWithAmpersand(),
|
|
222
|
+
node: rule,
|
|
223
|
+
index: 0,
|
|
224
|
+
endIndex: rule.selector.length,
|
|
225
|
+
result: postcssResult,
|
|
226
|
+
ruleName,
|
|
227
|
+
fix: () => {
|
|
228
|
+
const a = selectorAST.nodes[0];
|
|
229
|
+
const b = selectorAST.nodes[1];
|
|
230
|
+
|
|
231
|
+
selectorAST.replaceWith(selectorParser.selector({
|
|
232
|
+
nodes: [
|
|
233
|
+
b,
|
|
234
|
+
a,
|
|
235
|
+
]
|
|
236
|
+
}));
|
|
237
|
+
|
|
238
|
+
rule.selector = selectorsAST.toString();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
223
242
|
continue;
|
|
224
243
|
}
|
|
225
244
|
|
|
226
245
|
// .foo { .bar {} }
|
|
227
246
|
if (selectorAST.nodes[0]?.type !== 'nesting') {
|
|
228
|
-
if (context.fix) {
|
|
229
|
-
fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
247
|
stylelint.utils.report({
|
|
234
248
|
message: messages.rejectedMustStartWithAmpersand(),
|
|
235
249
|
node: rule,
|
|
@@ -237,6 +251,9 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
237
251
|
endIndex: rule.selector.length,
|
|
238
252
|
result: postcssResult,
|
|
239
253
|
ruleName,
|
|
254
|
+
fix: () => {
|
|
255
|
+
fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector);
|
|
256
|
+
}
|
|
240
257
|
});
|
|
241
258
|
|
|
242
259
|
continue;
|
|
@@ -244,22 +261,6 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
244
261
|
|
|
245
262
|
// .foo { & + .bar {} }
|
|
246
263
|
if (selectorAST.nodes.length !== 2) {
|
|
247
|
-
if (context.fix) {
|
|
248
|
-
|
|
249
|
-
const firstPart = selectorAST.nodes[0];
|
|
250
|
-
const afterFirstPart = selectorAST.nodes[0]?.next();
|
|
251
|
-
|
|
252
|
-
if (firstPart && afterFirstPart?.type === 'combinator') {
|
|
253
|
-
selectorAST.nodes[0]?.replaceWith(selectorParser.nesting())
|
|
254
|
-
fixSelector(rule, selectorsAST, selectorAST);
|
|
255
|
-
} else {
|
|
256
|
-
selectorAST.nodes[0]?.remove();
|
|
257
|
-
fixSelector(rule, selectorsAST, selectorAST);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
264
|
stylelint.utils.report({
|
|
264
265
|
message: messages.rejectedNestingSelectorIncorrectShape(),
|
|
265
266
|
node: rule,
|
|
@@ -267,6 +268,18 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
267
268
|
endIndex: rule.selector.length,
|
|
268
269
|
result: postcssResult,
|
|
269
270
|
ruleName,
|
|
271
|
+
fix: () => {
|
|
272
|
+
const firstPart = selectorAST.nodes[0];
|
|
273
|
+
const afterFirstPart = selectorAST.nodes[0]?.next();
|
|
274
|
+
|
|
275
|
+
if (firstPart && afterFirstPart?.type === 'combinator') {
|
|
276
|
+
selectorAST.nodes[0]?.replaceWith(selectorParser.nesting())
|
|
277
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
278
|
+
} else {
|
|
279
|
+
selectorAST.nodes[0]?.remove();
|
|
280
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
270
283
|
});
|
|
271
284
|
|
|
272
285
|
continue;
|
|
@@ -274,12 +287,6 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
274
287
|
|
|
275
288
|
// .foo { &.bar {} }
|
|
276
289
|
if (selectorAST.nodes[1]?.type !== 'pseudo') {
|
|
277
|
-
if (context.fix) {
|
|
278
|
-
selectorAST.nodes[0]?.remove();
|
|
279
|
-
fixSelector(rule, selectorsAST, selectorAST);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
290
|
stylelint.utils.report({
|
|
284
291
|
message: messages.rejectedMustEndWithPseudo(),
|
|
285
292
|
node: rule,
|
|
@@ -287,6 +294,10 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
287
294
|
endIndex: rule.selector.length,
|
|
288
295
|
result: postcssResult,
|
|
289
296
|
ruleName,
|
|
297
|
+
fix: () => {
|
|
298
|
+
selectorAST.nodes[0]?.remove();
|
|
299
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
300
|
+
}
|
|
290
301
|
});
|
|
291
302
|
|
|
292
303
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrhenry/stylelint-mrhenry-nesting",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Mr. Henry's preferred way of writing nested CSS",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"stylelint-plugin"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@csstools/selector-specificity": "^
|
|
32
|
-
"postcss-selector-parser": "^6.
|
|
31
|
+
"@csstools/selector-specificity": "^4.0.0",
|
|
32
|
+
"postcss-selector-parser": "^6.1.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"stylelint": "^16.
|
|
35
|
+
"stylelint": "^16.8.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"stylelint": "^16.
|
|
38
|
+
"stylelint": "^16.8.2"
|
|
39
39
|
}
|
|
40
40
|
}
|