From 387456648ed03a9e04f4602d5771080ff8716f55 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:41:42 +0000 Subject: [PATCH] Fix `property-no-unknown` false negatives for newer custom syntaxes (#6553) Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- .changeset/empty-goats-count.md | 5 +++++ .../isStandardSyntaxDeclaration.test.js | 4 ++++ lib/utils/isStandardSyntaxDeclaration.js | 21 +------------------ 3 files changed, 10 insertions(+), 20 deletions(-) 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 diff --git a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js index fcce7bba53..8c928ee3aa 100644 --- a/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js +++ b/lib/utils/__tests__/isStandardSyntaxDeclaration.test.js @@ -166,6 +166,10 @@ describe('isStandardSyntaxDeclaration', () => { true, ); }); + + it('supports root-level declarations', () => { + expect(isStandardSyntaxDeclaration(decl('color: yellow;'))).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;