@csstools/stylelint-at-risk 1.0.0 → 2.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.
- package/index.mjs +76 -20
- package/package.json +4 -3
package/index.mjs
CHANGED
|
@@ -6,8 +6,24 @@ const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
|
6
6
|
rejectedNestingDeclOrder: () => {
|
|
7
7
|
return 'Declarations after nested rules or at-rules are currently re-ordered but might not be in the future. Place all declarations before any nested rules or at-rules to prevent future compat issues.';
|
|
8
8
|
},
|
|
9
|
+
rejectedAtRiskPropertyReplacement: (atRisk, replacement) => {
|
|
10
|
+
return `The '${atRisk}' property is being replaced with '${replacement}'.`;
|
|
11
|
+
},
|
|
12
|
+
rejectedAtRiskPropertyRemoval: (atRisk) => {
|
|
13
|
+
return `The '${atRisk}' property is being removed.`;
|
|
14
|
+
},
|
|
9
15
|
});
|
|
10
16
|
|
|
17
|
+
const atRiskProperties = {
|
|
18
|
+
replacements: [
|
|
19
|
+
[
|
|
20
|
+
'inset-area',
|
|
21
|
+
'position-area',
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
removals: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
11
27
|
const meta = {
|
|
12
28
|
url: 'https://github.com/csstools/postcss-plugins/blob/main/plugins-stylelint/at-risk',
|
|
13
29
|
fixable: true,
|
|
@@ -22,32 +38,72 @@ const ruleFunction = (primaryOption) => {
|
|
|
22
38
|
// Nested Declarations after Rules/At-Rules
|
|
23
39
|
{
|
|
24
40
|
postcssRoot.walkDecls((decl) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
prev = prev.prev();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!prev) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (prev?.type !== 'decl') {
|
|
36
|
-
stylelint.utils.report({
|
|
37
|
-
message: messages.rejectedNestingDeclOrder(),
|
|
38
|
-
node: decl,
|
|
39
|
-
index: 0,
|
|
40
|
-
endIndex: 5,
|
|
41
|
-
result: postcssResult,
|
|
42
|
-
ruleName,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
41
|
+
checkNestingDeclOrder(decl, postcssResult);
|
|
42
|
+
|
|
43
|
+
checkAtRiskProperties(decl, postcssResult);
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
49
|
|
|
50
|
+
function checkNestingDeclOrder(decl, postcssResult) {
|
|
51
|
+
let prev = decl.prev();
|
|
52
|
+
|
|
53
|
+
while (prev && prev.type === 'comment') {
|
|
54
|
+
prev = prev.prev();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!prev) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (prev?.type !== 'decl') {
|
|
62
|
+
stylelint.utils.report({
|
|
63
|
+
message: messages.rejectedNestingDeclOrder(),
|
|
64
|
+
node: decl,
|
|
65
|
+
index: 0,
|
|
66
|
+
endIndex: decl.prop.length,
|
|
67
|
+
result: postcssResult,
|
|
68
|
+
ruleName,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function checkAtRiskProperties(decl, postcssResult) {
|
|
74
|
+
const lowerCaseProp = decl.prop.toLowerCase();
|
|
75
|
+
|
|
76
|
+
atRiskProperties.replacements.forEach(([atRisk, replacement]) => {
|
|
77
|
+
if (lowerCaseProp !== atRisk) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
stylelint.utils.report({
|
|
82
|
+
message: messages.rejectedAtRiskPropertyReplacement(atRisk, replacement),
|
|
83
|
+
node: decl,
|
|
84
|
+
index: 0,
|
|
85
|
+
endIndex: decl.prop.length,
|
|
86
|
+
result: postcssResult,
|
|
87
|
+
ruleName,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
atRiskProperties.removals.forEach((atRisk) => {
|
|
92
|
+
if (lowerCaseProp !== atRisk) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
stylelint.utils.report({
|
|
97
|
+
message: messages.rejectedAtRiskPropertyRemoval(atRisk),
|
|
98
|
+
node: decl,
|
|
99
|
+
index: 0,
|
|
100
|
+
endIndex: decl.prop.length,
|
|
101
|
+
result: postcssResult,
|
|
102
|
+
ruleName,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
51
107
|
ruleFunction.ruleName = ruleName;
|
|
52
108
|
ruleFunction.messages = messages;
|
|
53
109
|
ruleFunction.meta = meta;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csstools/stylelint-at-risk",
|
|
3
3
|
"description": "Warn on CSS features at risk of changes or removal",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
27
|
"engines": {
|
|
28
|
-
"node": "
|
|
28
|
+
"node": ">=18"
|
|
29
29
|
},
|
|
30
30
|
"type": "module",
|
|
31
31
|
"main": "index.mjs",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"index.mjs"
|
|
36
36
|
],
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"stylelint": "^16.
|
|
38
|
+
"stylelint": "^16.8.0"
|
|
39
39
|
},
|
|
40
|
+
"scripts": {},
|
|
40
41
|
"homepage": "https://github.com/csstools/postcss-plugins/blob/main/plugins-stylelint/at-risk#readme",
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|