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