Skip to content

Commit 0a5f75b

Browse files
authored
Fix at-rule-no-deprecated false positives for @apply (#8630)
1 parent 0a77412 commit 0a5f75b

File tree

6 files changed

+115
-14
lines changed

6 files changed

+115
-14
lines changed

.changeset/pink-spoons-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": patch
3+
---
4+
5+
Fixed: `at-rule-no-deprecated` false positives for `@apply`

lib/reference/atKeywords.cjs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/reference/atKeywords.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import uniteSets from '../utils/uniteSets.mjs';
22

33
/** @type {ReadonlySet<string>} */
4-
export const deprecatedAtKeywords = new Set(['apply', 'document', 'nest', 'viewport']);
4+
export const deprecatedAtKeywords = new Set(['document', 'nest', 'viewport']);
55

66
/**
77
* @see https://www.w3.org/TR/css-nesting-1/#conditionals
88
* @type {ReadonlySet<string>}
99
*/
1010
export const nestingSupportedAtKeywords = new Set([
11+
'apply',
1112
'container',
1213
'layer',
1314
'media',

lib/rules/at-rule-descriptor-no-unknown/__tests__/index.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import rule from '../index.mjs';
2+
import { stripIndent } from 'common-tags';
3+
24
const { messages, ruleName } = rule;
35

46
testRule({
@@ -153,5 +155,53 @@ testRule({
153155
},
154156
],
155157
},
158+
{
159+
code: stripIndent`
160+
@mixin --qux-baz(@contents) {
161+
@supports (overflow-anchor: auto) {
162+
@contents;
163+
}
164+
}
165+
166+
body {
167+
@apply --qux-baz {
168+
@font-face {
169+
foo: normal;
170+
}
171+
}
172+
}
173+
`,
174+
message: messages.rejected('@font-face', 'foo'),
175+
line: 10,
176+
column: 5,
177+
endLine: 10,
178+
endColumn: 8,
179+
description: 'without indirection',
180+
},
181+
{
182+
code: stripIndent`
183+
@mixin --qux-baz(@contents) {
184+
@supports (overflow-anchor: auto) {
185+
@font-face {
186+
@contents;
187+
}
188+
}
189+
}
190+
191+
body {
192+
@apply --qux-baz {
193+
foo: normal;
194+
}
195+
}
196+
`,
197+
message: messages.rejected('@font-face', 'foo'),
198+
line: 11,
199+
column: 3,
200+
endLine: 11,
201+
endColumn: 6,
202+
description: 'with indirection',
203+
// TODO: unskip once we support @mixin indirection
204+
skip: true,
205+
},
156206
],
157207
});

lib/rules/at-rule-descriptor-value-no-unknown/__tests__/index.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import rule from '../index.mjs';
2+
import { stripIndent } from 'common-tags';
3+
24
const { messages, ruleName } = rule;
35

46
testRule({
@@ -89,5 +91,53 @@ testRule({
8991
endColumn: 55,
9092
description: 'an unknown value in a nested at-rule',
9193
},
94+
{
95+
code: stripIndent`
96+
@mixin --qux-baz(@contents) {
97+
@supports (overflow-anchor: auto) {
98+
@contents;
99+
}
100+
}
101+
102+
body {
103+
@apply --qux-baz {
104+
@font-face {
105+
ascent-override: foo;
106+
}
107+
}
108+
}
109+
`,
110+
message: messages.rejected('ascent-override', 'foo'),
111+
line: 10,
112+
column: 22,
113+
endLine: 10,
114+
endColumn: 25,
115+
description: 'without indirection',
116+
},
117+
{
118+
code: stripIndent`
119+
@mixin --qux-baz(@contents) {
120+
@supports (overflow-anchor: auto) {
121+
@font-face {
122+
@contents;
123+
}
124+
}
125+
}
126+
127+
body {
128+
@apply --qux-baz {
129+
ascent-override: foo;
130+
}
131+
}
132+
`,
133+
message: messages.rejected('ascent-override', 'foo'),
134+
line: 11,
135+
column: 20,
136+
endLine: 11,
137+
endColumn: 23,
138+
description: 'with indirection',
139+
// TODO: unskip once we support @mixin indirection
140+
skip: true,
141+
},
92142
],
93143
});

lib/rules/at-rule-no-deprecated/__tests__/index.mjs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ testRule({
2020
{
2121
code: '@CONTAINER (min-width: 500px) {}',
2222
},
23+
{
24+
code: 'a { @apply --foo; }',
25+
},
2326
],
2427

2528
reject: [
@@ -67,15 +70,6 @@ testRule({
6770
text: '',
6871
},
6972
},
70-
{
71-
code: 'a { @apply foo; }',
72-
unfixable: true,
73-
message: messages.rejected('@apply'),
74-
line: 1,
75-
column: 5,
76-
endLine: 1,
77-
endColumn: 11,
78-
},
7973
{
8074
code: 'a { @nest .foo {} @nest .bar {} }',
8175
fixed: 'a { .foo {} .bar {} }',
@@ -120,12 +114,12 @@ testRule({
120114

121115
reject: [
122116
{
123-
code: 'a { @apply foo; }',
124-
message: messages.rejected('@apply'),
117+
code: 'a { @nest .foo & {} }',
118+
message: messages.rejected('@nest'),
125119
line: 1,
126120
column: 5,
127121
endLine: 1,
128-
endColumn: 11,
122+
endColumn: 10,
129123
},
130124
],
131125
});

0 commit comments

Comments
 (0)