stylelint-plugin-defensive-css 0.0.2 → 0.0.5
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/package.json
CHANGED
|
@@ -15,7 +15,7 @@ const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
|
|
|
15
15
|
return 'Flex rows must have a `flex-wrap: wrap;` or `flex-wrap: wrap-reverse` declaration.';
|
|
16
16
|
},
|
|
17
17
|
vendorPrefixWGrouping() {
|
|
18
|
-
return `
|
|
18
|
+
return `Separate different vendor prefixes into their own rules.`;
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -8,20 +8,23 @@ const {
|
|
|
8
8
|
} = require('../../utils/findShorthandBackgroundRepeat');
|
|
9
9
|
const { findVendorPrefixes } = require('../../utils/findVendorPrefixes');
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
nodeToReport: undefined,
|
|
23
|
-
};
|
|
11
|
+
const defaultBackgroundRepeatProps = {
|
|
12
|
+
hasBackgroundImage: false,
|
|
13
|
+
isMissingBackgroundRepeat: true,
|
|
14
|
+
nodeToReport: undefined,
|
|
15
|
+
};
|
|
16
|
+
const defaultFlexWrappingProps = {
|
|
17
|
+
isDisplayFlex: false,
|
|
18
|
+
isFlexRow: true,
|
|
19
|
+
isMissingFlexWrap: true,
|
|
20
|
+
nodeToReport: undefined,
|
|
21
|
+
};
|
|
24
22
|
|
|
23
|
+
let backgroundRepeatProps = { ...defaultBackgroundRepeatProps };
|
|
24
|
+
let flexWrappingProps = { ...defaultFlexWrappingProps };
|
|
25
|
+
let isLastStyleDeclaration = false;
|
|
26
|
+
|
|
27
|
+
const ruleFunction = (_, options) => {
|
|
25
28
|
return (root, result) => {
|
|
26
29
|
const validOptions = stylelint.utils.validateOptions(result, ruleName);
|
|
27
30
|
|
|
@@ -30,12 +33,9 @@ const ruleFunction = (_, options) => {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
root.walkDecls((decl) => {
|
|
33
|
-
|
|
36
|
+
isLastStyleDeclaration =
|
|
34
37
|
JSON.stringify(decl) ===
|
|
35
|
-
JSON.stringify(decl.parent.nodes[decl.parent.nodes.length - 1])
|
|
36
|
-
) {
|
|
37
|
-
isLastStyleDeclaration = true;
|
|
38
|
-
}
|
|
38
|
+
JSON.stringify(decl.parent.nodes[decl.parent.nodes.length - 1]);
|
|
39
39
|
|
|
40
40
|
/* BACKGROUND REPEAT */
|
|
41
41
|
if (options?.['background-repeat']) {
|
|
@@ -55,16 +55,17 @@ const ruleFunction = (_, options) => {
|
|
|
55
55
|
backgroundRepeatProps.isMissingBackgroundRepeat = false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
if (isLastStyleDeclaration) {
|
|
59
|
+
if (Object.values(backgroundRepeatProps).every((prop) => prop)) {
|
|
60
|
+
stylelint.utils.report({
|
|
61
|
+
message: ruleMessages.backgroundRepeat(),
|
|
62
|
+
node: decl.parent,
|
|
63
|
+
result,
|
|
64
|
+
ruleName,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
backgroundRepeatProps = { ...defaultBackgroundRepeatProps };
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -95,16 +96,17 @@ const ruleFunction = (_, options) => {
|
|
|
95
96
|
flexWrappingProps.isMissingFlexWrap = false;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
if (isLastStyleDeclaration) {
|
|
100
|
+
if (Object.values(flexWrappingProps).every((prop) => prop)) {
|
|
101
|
+
stylelint.utils.report({
|
|
102
|
+
message: ruleMessages.flexWrapping(),
|
|
103
|
+
node: flexWrappingProps.nodeToReport,
|
|
104
|
+
result,
|
|
105
|
+
ruleName,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
flexWrappingProps = { ...defaultFlexWrappingProps };
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
|