From 3ed733f813188ce88389934afc9575717b62c974 Mon Sep 17 00:00:00 2001 From: 43081j <43081j@users.noreply.github.com> Date: Mon, 2 Jan 2023 19:04:03 +0000 Subject: [PATCH 1/3] fix: consider ruleless declarations as standard --- .../isStandardSyntaxDeclaration.test.js | 10 +++++++++ lib/utils/isStandardSyntaxDeclaration.js | 21 +------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js index fcce7bba53..5e145f0546 100644 --- a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js +++ b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js @@ -166,6 +166,16 @@ describe('isStandardSyntaxDeclaration', () => { true, ); }); + + it('supports root-level declarations', () => { + const doc = new postcss.Document(); + const root = postcss.parse('color: yellow;'); + + root.parent = doc; + doc.nodes.push(root); + + expect(isStandardSyntaxDeclaration(root.nodes[0])).toBe(true); + }); }); function decl(css, parser = postcss) { diff --git a/lib/utils/isStandardSyntaxDeclaration.js b/lib/utils/isStandardSyntaxDeclaration.js index 2f1f8b5787..e258a7d89f 100644 --- a/lib/utils/isStandardSyntaxDeclaration.js +++ b/lib/utils/isStandardSyntaxDeclaration.js @@ -1,14 +1,7 @@ 'use strict'; const isScssVariable = require('./isScssVariable'); -const { isRoot, isRule } = require('./typeGuards'); - -/** - * @param {string} [lang] - */ -function isStandardSyntaxLang(lang) { - return lang && (lang === 'css' || lang === 'custom-template' || lang === 'template-literal'); -} +const { isRule } = require('./typeGuards'); /** * Check whether a declaration is standard @@ -19,18 +12,6 @@ module.exports = function isStandardSyntaxDeclaration(decl) { const prop = decl.prop; const parent = decl.parent; - // Declarations belong in a declaration block or standard CSS source - if ( - parent && - isRoot(parent) && - parent.source && - !isStandardSyntaxLang( - /** @type {import('postcss').Source & {lang?: string}} */ (parent.source).lang, - ) - ) { - return false; - } - // SCSS var; covers map and list declarations if (isScssVariable(prop)) { return false; From 8323ba893bc1302512620c377e6b17c5e6a4dd5a Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:11:08 +0900 Subject: [PATCH 2/3] Add changelog entry --- .changeset/empty-goats-count.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/empty-goats-count.md diff --git a/.changeset/empty-goats-count.md b/.changeset/empty-goats-count.md new file mode 100644 index 0000000000..08cca0d360 --- /dev/null +++ b/.changeset/empty-goats-count.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `property-no-unknown` false negatives for newer custom syntaxes From 54a5098129ffd3cbd7b2f55d9320935d65d94774 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 5 Jan 2023 18:34:30 +0900 Subject: [PATCH 3/3] Simplify test case --- lib/utils/__tests__/isStandardSyntaxDeclaration.test.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js index 5e145f0546..8c928ee3aa 100644 --- a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js +++ b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js @@ -168,13 +168,7 @@ describe('isStandardSyntaxDeclaration', () => { }); it('supports root-level declarations', () => { - const doc = new postcss.Document(); - const root = postcss.parse('color: yellow;'); - - root.parent = doc; - doc.nodes.push(root); - - expect(isStandardSyntaxDeclaration(root.nodes[0])).toBe(true); + expect(isStandardSyntaxDeclaration(decl('color: yellow;'))).toBe(true); }); });