@csstools/stylelint-at-risk 1.0.0 → 2.0.1

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 +76 -21
  2. package/package.json +4 -3
package/index.mjs CHANGED
@@ -6,11 +6,26 @@ 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
- fixable: true,
14
29
  };
15
30
 
16
31
  const ruleFunction = (primaryOption) => {
@@ -22,32 +37,72 @@ const ruleFunction = (primaryOption) => {
22
37
  // Nested Declarations after Rules/At-Rules
23
38
  {
24
39
  postcssRoot.walkDecls((decl) => {
25
- let prev = decl.prev();
26
-
27
- while (prev && prev.type === 'comment') {
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
- }
40
+ checkNestingDeclOrder(decl, postcssResult);
41
+
42
+ checkAtRiskProperties(decl, postcssResult);
45
43
  });
46
44
  }
47
45
 
48
46
  };
49
47
  };
50
48
 
49
+ function checkNestingDeclOrder(decl, postcssResult) {
50
+ let prev = decl.prev();
51
+
52
+ while (prev && prev.type === 'comment') {
53
+ prev = prev.prev();
54
+ }
55
+
56
+ if (!prev) {
57
+ return;
58
+ }
59
+
60
+ if (prev?.type !== 'decl') {
61
+ stylelint.utils.report({
62
+ message: messages.rejectedNestingDeclOrder(),
63
+ node: decl,
64
+ index: 0,
65
+ endIndex: decl.prop.length,
66
+ result: postcssResult,
67
+ ruleName,
68
+ });
69
+ }
70
+ }
71
+
72
+ function checkAtRiskProperties(decl, postcssResult) {
73
+ const lowerCaseProp = decl.prop.toLowerCase();
74
+
75
+ atRiskProperties.replacements.forEach(([atRisk, replacement]) => {
76
+ if (lowerCaseProp !== atRisk) {
77
+ return;
78
+ }
79
+
80
+ stylelint.utils.report({
81
+ message: messages.rejectedAtRiskPropertyReplacement(atRisk, replacement),
82
+ node: decl,
83
+ index: 0,
84
+ endIndex: decl.prop.length,
85
+ result: postcssResult,
86
+ ruleName,
87
+ });
88
+ });
89
+
90
+ atRiskProperties.removals.forEach((atRisk) => {
91
+ if (lowerCaseProp !== atRisk) {
92
+ return;
93
+ }
94
+
95
+ stylelint.utils.report({
96
+ message: messages.rejectedAtRiskPropertyRemoval(atRisk),
97
+ node: decl,
98
+ index: 0,
99
+ endIndex: decl.prop.length,
100
+ result: postcssResult,
101
+ ruleName,
102
+ });
103
+ });
104
+ }
105
+
51
106
  ruleFunction.ruleName = ruleName;
52
107
  ruleFunction.messages = messages;
53
108
  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": "1.0.0",
4
+ "version": "2.0.1",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "Antonio Laguna",
@@ -25,7 +25,7 @@
25
25
  }
26
26
  ],
27
27
  "engines": {
28
- "node": "^14 || ^16 || >=18"
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.2.1"
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",