@mrhenry/stylelint-mrhenry-nesting 2.2.2 → 3.0.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
|
+
import selectorParser from 'postcss-selector-parser';
|
|
3
3
|
|
|
4
4
|
const ruleName = "@mrhenry/stylelint-mrhenry-nesting";
|
|
5
5
|
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
@@ -64,6 +64,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
|
64
64
|
while (parent) {
|
|
65
65
|
if (parent.type === 'rule') {
|
|
66
66
|
rulesDepth++;
|
|
67
|
+
break;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
parent = parent.parent;
|
|
@@ -92,6 +93,10 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
|
92
93
|
rulesDepth++;
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
if (rulesDepth > 2) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
95
100
|
parent = parent.parent;
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -114,7 +119,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
|
114
119
|
const selectorsAST = selectorParser().astSync(rule.selector);
|
|
115
120
|
const firstCompoundOrSelf = getFirstCompoundOrSelf(selectorsAST);
|
|
116
121
|
|
|
117
|
-
isRelativeSelector = false;
|
|
122
|
+
let isRelativeSelector = false;
|
|
118
123
|
if (firstCompoundOrSelf.nodes[0]?.type === 'combinator') {
|
|
119
124
|
isRelativeSelector = true;
|
|
120
125
|
}
|
|
@@ -167,7 +172,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
|
167
172
|
// .foo { .bar {} }
|
|
168
173
|
if (selectorAST.nodes[0]?.type !== 'nesting') {
|
|
169
174
|
if (context.fix) {
|
|
170
|
-
fixSelector(rule, selectorsAST, selectorAST);
|
|
175
|
+
fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector);
|
|
171
176
|
continue;
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -237,7 +242,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
|
|
|
237
242
|
};
|
|
238
243
|
};
|
|
239
244
|
|
|
240
|
-
function fixSelector(rule, selectorsAST, selectorAST) {
|
|
245
|
+
function fixSelector(rule, selectorsAST, selectorAST, isRelativeSelector) {
|
|
241
246
|
if (
|
|
242
247
|
selectorAST.nodes.length === 1 &&
|
|
243
248
|
selectorAST.nodes[0].type === 'pseudo'
|
|
@@ -289,16 +294,22 @@ ruleFunction.ruleName = ruleName;
|
|
|
289
294
|
ruleFunction.messages = messages;
|
|
290
295
|
ruleFunction.meta = meta;
|
|
291
296
|
|
|
292
|
-
|
|
297
|
+
export default stylelint.createPlugin(ruleName, ruleFunction);
|
|
293
298
|
|
|
294
299
|
function getFirstCompoundOrSelf(x) {
|
|
300
|
+
/* c8 ignore next */
|
|
295
301
|
if (!x.nodes) {
|
|
302
|
+
/* c8 ignore next */
|
|
296
303
|
return x;
|
|
304
|
+
/* c8 ignore next */
|
|
297
305
|
}
|
|
298
306
|
|
|
299
307
|
for (let i = 0; i < x.nodes.length; i++) {
|
|
308
|
+
/* c8 ignore next */
|
|
300
309
|
if (x.nodes[i].type !== 'selector') {
|
|
310
|
+
/* c8 ignore next */
|
|
301
311
|
return x;
|
|
312
|
+
/* c8 ignore next */
|
|
302
313
|
}
|
|
303
314
|
}
|
|
304
315
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrhenry/stylelint-mrhenry-nesting",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Mr. Henry's preferred way of writing nested CSS",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "index.mjs",
|
|
9
10
|
"scripts": {
|
|
10
|
-
"test": "
|
|
11
|
-
"test:jest": "c8 --100 jest"
|
|
11
|
+
"test": "c8 --100 node --test"
|
|
12
12
|
},
|
|
13
13
|
"author": "Mr. Henry",
|
|
14
14
|
"license": "MIT",
|
|
@@ -19,13 +19,10 @@
|
|
|
19
19
|
"directory": "packages/nesting"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"
|
|
22
|
+
"index.mjs",
|
|
23
23
|
"LICENSE",
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
|
-
"jest": {
|
|
27
|
-
"preset": "jest-preset-stylelint"
|
|
28
|
-
},
|
|
29
26
|
"keywords": [
|
|
30
27
|
"stylelint",
|
|
31
28
|
"stylelint-plugin"
|
|
@@ -34,9 +31,9 @@
|
|
|
34
31
|
"postcss-selector-parser": "^6.0.11"
|
|
35
32
|
},
|
|
36
33
|
"peerDependencies": {
|
|
37
|
-
"stylelint": "^
|
|
34
|
+
"stylelint": "^16.0.0"
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
|
40
|
-
"stylelint": "^
|
|
37
|
+
"stylelint": "^16.0.2"
|
|
41
38
|
}
|
|
42
39
|
}
|