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 all 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
9 changes: 9 additions & 0 deletions lib/reference/__tests__/atKeywords.test.mjs
@@ -0,0 +1,9 @@
import { atKeywords, nestingSupportedAtKeywords } from '../atKeywords.js';

describe('atKeywords', () => {
it('nestingSupportedAtKeywords is a subset of all atKeywords', () => {
for (const keyword of nestingSupportedAtKeywords) {
expect(atKeywords).toContain(keyword);
}
});
});
romainmenke marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions lib/reference/atKeywords.js
Expand Up @@ -2,6 +2,9 @@

const uniteSets = require('../utils/uniteSets.js');

// https://www.w3.org/TR/css-nesting-1/#conditionals
const nestingSupportedAtKeywords = new Set(['container', 'layer', 'media', 'scope', 'supports']);
romainmenke marked this conversation as resolved.
Show resolved Hide resolved

// https://www.w3.org/TR/css-page-3/#syntax-page-selector
const pageMarginAtKeywords = new Set([
'top-left-corner',
Expand Down Expand Up @@ -45,6 +48,7 @@ const atKeywords = uniteSets(pageMarginAtKeywords, [
'page',
'property',
'scroll-timeline',
'scope',
'styleset',
'stylistic',
'supports',
Expand All @@ -54,4 +58,5 @@ const atKeywords = uniteSets(pageMarginAtKeywords, [

module.exports = {
atKeywords,
nestingSupportedAtKeywords,
};
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 2 additions & 1 deletion lib/rules/declaration-property-value-no-unknown/index.js
Expand Up @@ -15,6 +15,7 @@ const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty')
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
const { isAtRule } = require('../../utils/typeGuards');
const { isRegExp, isString } = require('../../utils/validateTypes');
const { nestingSupportedAtKeywords } = require('../../reference/atKeywords');

const ruleName = 'declaration-property-value-no-unknown';

Expand Down Expand Up @@ -111,7 +112,7 @@ const rule = (primary, secondaryOptions) => {
}

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

Expand Down