@mrhenry/stylelint-mrhenry-nesting 3.1.3 → 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.
Files changed (2) hide show
  1. package/index.mjs +62 -30
  2. package/package.json +5 -5
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
- fixSelector_AncestorPattern(rule, selectorsAST, selectorAST);
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
- 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();
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
- fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector);
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
- 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
- }
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
- selectorAST.nodes[0]?.remove();
298
- fixSelector(rule, selectorsAST, selectorAST);
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.1.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"
@@ -28,13 +28,13 @@
28
28
  "stylelint-plugin"
29
29
  ],
30
30
  "dependencies": {
31
- "@csstools/selector-specificity": "^4.0.0",
32
- "postcss-selector-parser": "^6.1.1"
31
+ "@csstools/selector-specificity": "^5.0.0",
32
+ "postcss-selector-parser": "^7.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "stylelint": "^16.8.2"
35
+ "stylelint": "^16.14.1"
36
36
  },
37
37
  "devDependencies": {
38
- "stylelint": "^16.8.2"
38
+ "stylelint": "^16.14.1"
39
39
  }
40
40
  }