Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix declaration-property-value-no-unknown false negatives for nested declarations #7079

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-pumas-march.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-property-value-no-unknown` false negatives for nested declarations
Expand Up @@ -9,6 +9,9 @@ testRule({
{
code: 'a { top: 0; }',
},
{
code: 'a { @media screen { top: 0; } }',
},
{
code: 'a { margin: auto 10em; }',
},
Expand Down Expand Up @@ -66,6 +69,14 @@ testRule({
endLine: 1,
endColumn: 17,
},
{
code: 'a { @media screen { top: unknown; } }',
message: messages.rejected('top', 'unknown'),
line: 1,
column: 26,
endLine: 1,
endColumn: 33,
},
{
code: 'a { top: red; }',
message: messages.rejected('top', 'red'),
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/declaration-property-value-no-unknown/index.js
Expand Up @@ -28,6 +28,8 @@ const meta = {
url: 'https://stylelint.io/user-guide/rules/declaration-property-value-no-unknown',
};

const CONDITIONAL_RULES_ALLOWED_IN_NESTING = /^(?:media|supports|layer|scope|container)$/i;
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

/** @type {import('stylelint').Rule} */
const rule = (primary, secondaryOptions) => {
return (root, result) => {
Expand Down Expand Up @@ -111,7 +113,7 @@ const rule = (primary, secondaryOptions) => {
}

const { error } =
parent && isAtRule(parent)
parent && isAtRule(parent) && !CONDITIONAL_RULES_ALLOWED_IN_NESTING.test(parent.name)
? forkedLexer.matchAtruleDescriptor(parent.name, prop, cssTreeValueNode)
: forkedLexer.matchProperty(prop, cssTreeValueNode);

Expand Down