@mrhenry/stylelint-mrhenry-nesting 3.1.4 → 3.2.0
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 +62 -30
- package/package.json +3 -3
package/index.mjs
CHANGED
|
@@ -166,6 +166,8 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
166
166
|
result: postcssResult,
|
|
167
167
|
ruleName,
|
|
168
168
|
});
|
|
169
|
+
|
|
170
|
+
return;
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
173
|
|
|
@@ -183,6 +185,21 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
183
185
|
continue;
|
|
184
186
|
}
|
|
185
187
|
|
|
188
|
+
// .foo { & {} }
|
|
189
|
+
// .foo { && {} }
|
|
190
|
+
if (selectorAST.nodes.every((x) => x.type === 'nesting' || x.type === 'comment')) {
|
|
191
|
+
stylelint.utils.report({
|
|
192
|
+
message: messages.rejectedNestingSelectorIncorrectShape(),
|
|
193
|
+
node: rule,
|
|
194
|
+
index: 0,
|
|
195
|
+
endIndex: rule.selector.length,
|
|
196
|
+
result: postcssResult,
|
|
197
|
+
ruleName,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
|
|
186
203
|
let nestingCounter = 0;
|
|
187
204
|
selectorAST.walkNesting(() => {
|
|
188
205
|
nestingCounter++;
|
|
@@ -201,8 +218,11 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
201
218
|
endIndex: rule.selector.length,
|
|
202
219
|
result: postcssResult,
|
|
203
220
|
ruleName,
|
|
204
|
-
fix:
|
|
205
|
-
|
|
221
|
+
fix: {
|
|
222
|
+
apply: () => {
|
|
223
|
+
fixSelector_AncestorPattern(rule, selectorsAST, selectorAST);
|
|
224
|
+
},
|
|
225
|
+
node: rule
|
|
206
226
|
}
|
|
207
227
|
});
|
|
208
228
|
|
|
@@ -223,18 +243,21 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
223
243
|
endIndex: rule.selector.length,
|
|
224
244
|
result: postcssResult,
|
|
225
245
|
ruleName,
|
|
226
|
-
fix:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
fix: {
|
|
247
|
+
apply: () => {
|
|
248
|
+
const a = selectorAST.nodes[0];
|
|
249
|
+
const b = selectorAST.nodes[1];
|
|
250
|
+
|
|
251
|
+
selectorAST.replaceWith(selectorParser.selector({
|
|
252
|
+
nodes: [
|
|
253
|
+
b,
|
|
254
|
+
a,
|
|
255
|
+
]
|
|
256
|
+
}));
|
|
257
|
+
|
|
258
|
+
rule.selector = selectorsAST.toString();
|
|
259
|
+
},
|
|
260
|
+
node: rule
|
|
238
261
|
}
|
|
239
262
|
});
|
|
240
263
|
|
|
@@ -250,8 +273,11 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
250
273
|
endIndex: rule.selector.length,
|
|
251
274
|
result: postcssResult,
|
|
252
275
|
ruleName,
|
|
253
|
-
fix:
|
|
254
|
-
|
|
276
|
+
fix: {
|
|
277
|
+
apply: () => {
|
|
278
|
+
fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector);
|
|
279
|
+
},
|
|
280
|
+
node: rule
|
|
255
281
|
}
|
|
256
282
|
});
|
|
257
283
|
|
|
@@ -267,17 +293,20 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
267
293
|
endIndex: rule.selector.length,
|
|
268
294
|
result: postcssResult,
|
|
269
295
|
ruleName,
|
|
270
|
-
fix:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
296
|
+
fix: {
|
|
297
|
+
apply: () => {
|
|
298
|
+
const firstPart = selectorAST.nodes[0];
|
|
299
|
+
const afterFirstPart = selectorAST.nodes[0]?.next();
|
|
300
|
+
|
|
301
|
+
if (firstPart && afterFirstPart?.type === 'combinator') {
|
|
302
|
+
selectorAST.nodes[0]?.replaceWith(selectorParser.nesting())
|
|
303
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
304
|
+
} else {
|
|
305
|
+
selectorAST.nodes[0]?.remove();
|
|
306
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
node: rule
|
|
281
310
|
}
|
|
282
311
|
});
|
|
283
312
|
|
|
@@ -293,9 +322,12 @@ const ruleFunction = (primaryOption, secondaryOption) => {
|
|
|
293
322
|
endIndex: rule.selector.length,
|
|
294
323
|
result: postcssResult,
|
|
295
324
|
ruleName,
|
|
296
|
-
fix:
|
|
297
|
-
|
|
298
|
-
|
|
325
|
+
fix: {
|
|
326
|
+
apply: () => {
|
|
327
|
+
selectorAST.nodes[0]?.remove();
|
|
328
|
+
fixSelector(rule, selectorsAST, selectorAST);
|
|
329
|
+
},
|
|
330
|
+
node: rule
|
|
299
331
|
}
|
|
300
332
|
});
|
|
301
333
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrhenry/stylelint-mrhenry-nesting",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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": "^7.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"stylelint": "^16.
|
|
35
|
+
"stylelint": "^16.14.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"stylelint": "^16.
|
|
38
|
+
"stylelint": "^16.14.1"
|
|
39
39
|
}
|
|
40
40
|
}
|