Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-spoons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `at-rule-no-deprecated` false positives for `@apply`
3 changes: 2 additions & 1 deletion lib/reference/atKeywords.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/reference/atKeywords.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import uniteSets from '../utils/uniteSets.mjs';

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

/**
* @see https://www.w3.org/TR/css-nesting-1/#conditionals
* @type {ReadonlySet<string>}
*/
export const nestingSupportedAtKeywords = new Set([
'apply',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] This change will seem to impact other rules than at-rule-no-deprecated. What is the reason for this addition to nestingSupportedAtKeywords?

Copy link
Member Author

@Mouvedia Mouvedia Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look further:

export const atKeywords = uniteSets(
deprecatedAtKeywords,
nestingSupportedAtKeywords,
pageMarginAtKeywords,
fontFeatureValueTypes,
[

It was already part of the atKeywords set hence the real regression would be to not include it back.
e.g. for at-rule-no-unknown

What is the reason for this addition to nestingSupportedAtKeywords?

That's because it can be nested in a block.
i.e. it doesn't have to be at the root like for example @font-face

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood the change's background. 👍🏼

So, I think we should clarify which rules are impacted by the nestingSupportedAtKeywords change in this PR. It should not be only for at-rule-no-deprecated. I'd suggest:

  • Add affected rules to the PR title and the changelog entry
  • Add test cases for the rules

Copy link
Member Author

@Mouvedia Mouvedia Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mixin declares a @contents parameter, and the @apply rule has a block…

Declarations are further categorized as property declarations or descriptor declarations

todo

  • tests
    • at-rule-descriptor-no-unknown
    • at-rule-descriptor-value-no-unknown
  • add separate changeset for at-rule-*-no-unknown

example for at-rule-descriptor-value-no-unknown

@mixin --qux-baz(@contents) {
  @supports (overflow-anchor: auto) {
    @font-face {
      @contents;
    }
  }
}

body {
  @apply --qux-baz {
    ascent-override: foo;
  }
}

cf https://www.phpied.com/supports-and-font-face-troubles/

Ill add the tests but if it requires change to the rules so that the error can be detected Ill skip: true them.
i.e. the indirection that @mixin may introduce is probably not supported by those rules yet

out of scope

'container',
'layer',
'media',
Expand Down
50 changes: 50 additions & 0 deletions lib/rules/at-rule-descriptor-no-unknown/__tests__/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import rule from '../index.mjs';
import { stripIndent } from 'common-tags';

const { messages, ruleName } = rule;

testRule({
Expand Down Expand Up @@ -153,5 +155,53 @@ testRule({
},
],
},
{
code: stripIndent`
@mixin --qux-baz(@contents) {
@supports (overflow-anchor: auto) {
@contents;
}
}

body {
@apply --qux-baz {
@font-face {
foo: normal;
}
}
}
`,
message: messages.rejected('@font-face', 'foo'),
line: 10,
column: 5,
endLine: 10,
endColumn: 8,
description: 'without indirection',
},
{
code: stripIndent`
@mixin --qux-baz(@contents) {
@supports (overflow-anchor: auto) {
@font-face {
@contents;
}
}
}

body {
@apply --qux-baz {
foo: normal;
}
}
Comment on lines +183 to +195
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`,
message: messages.rejected('@font-face', 'foo'),
line: 11,
column: 3,
endLine: 11,
endColumn: 6,
description: 'with indirection',
// TODO: unskip once we support @mixin indirection
skip: true,
},
],
});
50 changes: 50 additions & 0 deletions lib/rules/at-rule-descriptor-value-no-unknown/__tests__/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import rule from '../index.mjs';
import { stripIndent } from 'common-tags';

const { messages, ruleName } = rule;

testRule({
Expand Down Expand Up @@ -89,5 +91,53 @@ testRule({
endColumn: 55,
description: 'an unknown value in a nested at-rule',
},
{
code: stripIndent`
@mixin --qux-baz(@contents) {
@supports (overflow-anchor: auto) {
@contents;
}
}
body {
@apply --qux-baz {
@font-face {
ascent-override: foo;
}
}
}
`,
message: messages.rejected('ascent-override', 'foo'),
line: 10,
column: 22,
endLine: 10,
endColumn: 25,
description: 'without indirection',
},
{
code: stripIndent`
@mixin --qux-baz(@contents) {
@supports (overflow-anchor: auto) {
@font-face {
@contents;
}
}
}
body {
@apply --qux-baz {
ascent-override: foo;
}
}
`,
message: messages.rejected('ascent-override', 'foo'),
line: 11,
column: 20,
endLine: 11,
endColumn: 23,
description: 'with indirection',
// TODO: unskip once we support @mixin indirection
skip: true,
},
],
});
18 changes: 6 additions & 12 deletions lib/rules/at-rule-no-deprecated/__tests__/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ testRule({
{
code: '@CONTAINER (min-width: 500px) {}',
},
{
code: 'a { @apply --foo; }',
},
],

reject: [
Expand Down Expand Up @@ -67,15 +70,6 @@ testRule({
text: '',
},
},
{
code: 'a { @apply foo; }',
unfixable: true,
message: messages.rejected('@apply'),
line: 1,
column: 5,
endLine: 1,
endColumn: 11,
},
{
code: 'a { @nest .foo {} @nest .bar {} }',
fixed: 'a { .foo {} .bar {} }',
Expand Down Expand Up @@ -120,12 +114,12 @@ testRule({

reject: [
{
code: 'a { @apply foo; }',
message: messages.rejected('@apply'),
code: 'a { @nest .foo & {} }',
message: messages.rejected('@nest'),
line: 1,
column: 5,
endLine: 1,
endColumn: 11,
endColumn: 10,
},
],
});