Skip to content

Commit c56bc2a

Browse files
immitsuMouvediajeddy3
authored
Add property-no-deprecated rule (#8682)
Co-authored-by: Gary Gozlan <[email protected]> Co-authored-by: Richard Hallows <[email protected]>
1 parent 91e8e6b commit c56bc2a

File tree

9 files changed

+515
-0
lines changed

9 files changed

+515
-0
lines changed

.changeset/whole-tips-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": minor
3+
---
4+
5+
Added: `property-no-deprecated` rule

docs/user-guide/rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Disallow deprecated things with these `no-deprecated` rules.
2121
| [`at-rule-no-deprecated`](../../lib/rules/at-rule-no-deprecated/README.md)<br/>Disallow deprecated at-rules. || 🔧 |
2222
| [`declaration-property-value-keyword-no-deprecated`](../../lib/rules/declaration-property-value-keyword-no-deprecated/README.md)<br/>Disallow deprecated keywords for properties within declarations. || 🔧 |
2323
| [`media-type-no-deprecated`](../../lib/rules/media-type-no-deprecated/README.md)<br/>Disallow deprecated media types. || |
24+
| [`property-no-deprecated`](../../lib/rules/property-no-deprecated/README.md)<br/>Disallow deprecated properties. || 🔧 |
2425
<!-- prettier-ignore-end -->
2526

2627
### Descending

lib/rules/index.cjs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ const rules = {
299299
get 'property-disallowed-list'() {
300300
return import('./property-disallowed-list/index.mjs').then((m) => m.default);
301301
},
302+
get 'property-no-deprecated'() {
303+
return import('./property-no-deprecated/index.mjs').then((m) => m.default);
304+
},
302305
get 'property-no-unknown'() {
303306
return import('./property-no-unknown/index.mjs').then((m) => m.default);
304307
},
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# property-no-deprecated
2+
3+
Disallow deprecated properties.
4+
5+
<!-- prettier-ignore -->
6+
```css
7+
a { word-wrap: break-word; }
8+
/** ↑
9+
* Deprecated property */
10+
```
11+
12+
This rule flags properties that were removed or deprecated after being in the CSS specifications, including editor drafts, and were either:
13+
14+
- shipped in a stable version of a browser
15+
- shipped by a developer channel/edition browser
16+
- shipped but behind experimental flags
17+
- polyfilled with some adoption before any browser actually shipped
18+
- had an MDN page at one point in time
19+
20+
The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix some of the problems reported by this rule.
21+
22+
Prior art:
23+
24+
- [@isnotdefined/no-obsolete](https://www.npmjs.com/package/@isnotdefined/stylelint-plugin)
25+
26+
## Options
27+
28+
### `true`
29+
30+
```json
31+
{
32+
"property-no-deprecated": true
33+
}
34+
```
35+
36+
The following patterns are considered problems:
37+
38+
<!-- prettier-ignore -->
39+
```css
40+
a { clip: rect(0, 0, 0, 0); }
41+
```
42+
43+
<!-- prettier-ignore -->
44+
```css
45+
a { word-wrap: break-word; }
46+
```
47+
48+
The following patterns are _not_ considered problems:
49+
50+
<!-- prettier-ignore -->
51+
```css
52+
a { clip-path: rect(0, 0, 0, 0); }
53+
```
54+
55+
<!-- prettier-ignore -->
56+
```css
57+
a { overflow-wrap: break-word; }
58+
```
59+
60+
## Optional secondary options
61+
62+
### `ignoreProperties`
63+
64+
```json
65+
{ "ignoreProperties": ["array", "of", "properties", "/regex/"] }
66+
```
67+
68+
Given:
69+
70+
```json
71+
{
72+
"property-no-deprecated": [true, { "ignoreProperties": ["clip", "/^grid-/"] }]
73+
}
74+
```
75+
76+
The following patterns are _not_ considered problems:
77+
78+
<!-- prettier-ignore -->
79+
```css
80+
a { clip: rect(0, 0, 0, 0); }
81+
```
82+
83+
<!-- prettier-ignore -->
84+
```css
85+
a { grid-row-gap: 4px; }
86+
```
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import rule from '../index.mjs';
2+
import { stripIndent } from 'common-tags';
3+
4+
const { messages, ruleName } = rule;
5+
6+
testRule({
7+
ruleName,
8+
config: [true],
9+
fix: true,
10+
computeEditInfo: true,
11+
12+
accept: [
13+
{
14+
code: 'a { clip-path: rect(0, 0, 0, 0); }',
15+
},
16+
],
17+
18+
reject: [
19+
{
20+
code: 'a { clip: rect(0, 0, 0, 0); }',
21+
fixed: 'a { clip-path: rect(0, 0, 0, 0); }',
22+
fix: {
23+
range: [7, 8],
24+
text: 'p-path',
25+
},
26+
message: messages.expected('clip', 'clip-path'),
27+
column: 5,
28+
endColumn: 9,
29+
line: 1,
30+
endLine: 1,
31+
},
32+
{
33+
code: 'a { /* comment */ clip: rect(0, 0, 0, 0); }',
34+
fixed: 'a { /* comment */ clip-path: rect(0, 0, 0, 0); }',
35+
fix: {
36+
range: [21, 22],
37+
text: 'p-path',
38+
},
39+
message: messages.expected('clip', 'clip-path'),
40+
column: 19,
41+
endColumn: 23,
42+
line: 1,
43+
endLine: 1,
44+
},
45+
{
46+
code: 'a { ime-mode: active; }',
47+
unfixable: true,
48+
message: messages.rejected('ime-mode'),
49+
column: 5,
50+
endColumn: 13,
51+
line: 1,
52+
endLine: 1,
53+
},
54+
{
55+
code: stripIndent`
56+
a {
57+
-moz-box-flex: revert;
58+
-moz-box-pack: start;
59+
}
60+
`,
61+
fixed: stripIndent`
62+
a {
63+
flex-grow: revert;
64+
-moz-box-pack: start;
65+
}
66+
`,
67+
warnings: [
68+
{
69+
message: messages.expected('-moz-box-flex', 'flex-grow'),
70+
fix: { range: [5, 18] },
71+
column: 2,
72+
endColumn: 15,
73+
line: 2,
74+
endLine: 2,
75+
},
76+
{
77+
message: messages.rejected('-moz-box-pack'),
78+
unfixable: true,
79+
column: 2,
80+
endColumn: 15,
81+
line: 3,
82+
endLine: 3,
83+
},
84+
],
85+
},
86+
],
87+
});
88+
89+
testRule({
90+
ruleName,
91+
config: [
92+
true,
93+
{
94+
ignoreProperties: [/^grid-/, 'word-wrap'],
95+
},
96+
],
97+
98+
accept: [
99+
{
100+
code: 'a { grid-column-gap: 1px; }',
101+
},
102+
{
103+
code: 'a { grid-gap: 1px; }',
104+
},
105+
{
106+
code: 'a { grid-row-gap: 1px; }',
107+
},
108+
{
109+
code: 'a { word-wrap: break-word; }',
110+
},
111+
],
112+
113+
reject: [
114+
{
115+
code: 'a { -webkit-user-modify: read-only; }',
116+
message: messages.rejected('-webkit-user-modify'),
117+
column: 5,
118+
endColumn: 24,
119+
line: 1,
120+
endLine: 1,
121+
},
122+
],
123+
});

lib/rules/property-no-deprecated/index.cjs

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)