stylelint-plugin-defensive-css 0.0.2 → 0.0.4
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,23 +55,26 @@ 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
|
}
|
|
70
|
+
|
|
71
|
+
return;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/* CUSTOM PROPERTY FALLBACKS */
|
|
72
75
|
if (options?.['custom-property-fallbacks']) {
|
|
73
76
|
if (decl.value.includes('var(--') && !decl.value.includes(',')) {
|
|
74
|
-
stylelint.utils.report({
|
|
77
|
+
return stylelint.utils.report({
|
|
75
78
|
message: ruleMessages.customPropertyFallbacks(),
|
|
76
79
|
node: decl,
|
|
77
80
|
result,
|
|
@@ -95,17 +98,20 @@ const ruleFunction = (_, options) => {
|
|
|
95
98
|
flexWrappingProps.isMissingFlexWrap = false;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
if (isLastStyleDeclaration) {
|
|
102
|
+
if (Object.values(flexWrappingProps).every((prop) => prop)) {
|
|
103
|
+
stylelint.utils.report({
|
|
104
|
+
message: ruleMessages.flexWrapping(),
|
|
105
|
+
node: flexWrappingProps.nodeToReport,
|
|
106
|
+
result,
|
|
107
|
+
ruleName,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
flexWrappingProps = { ...defaultFlexWrappingProps };
|
|
108
112
|
}
|
|
113
|
+
|
|
114
|
+
return;
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
/* GROUPING VENDOR PREFIXES */
|
|
@@ -113,7 +119,7 @@ const ruleFunction = (_, options) => {
|
|
|
113
119
|
const hasMultiplePrefixes = findVendorPrefixes(decl.parent.selector);
|
|
114
120
|
|
|
115
121
|
if (hasMultiplePrefixes) {
|
|
116
|
-
stylelint.utils.report({
|
|
122
|
+
return stylelint.utils.report({
|
|
117
123
|
message: ruleMessages.vendorPrefixWGrouping(),
|
|
118
124
|
node: decl.parent,
|
|
119
125
|
result,
|