From e5ae20b5bb11b128be8e530b6bc9d61fb588c602 Mon Sep 17 00:00:00 2001 From: hverlin Date: Sun, 14 Nov 2021 10:09:23 +0100 Subject: [PATCH 1/2] Fix false positives for SVG type selectors in selector-type-case (#5712) --- .gitignore | 1 + lib/reference/keywordSets.js | 36 +++++++++++++++++++ .../selector-type-case/__tests__/index.js | 8 +++++ lib/rules/selector-type-case/index.js | 5 +++ 4 files changed, 50 insertions(+) diff --git a/.gitignore b/.gitignore index 44fb258e98..cdf585c505 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .coverage .eslintcache yarn.lock +.idea diff --git a/lib/reference/keywordSets.js b/lib/reference/keywordSets.js index 0b632a35a2..4e6a4a9808 100644 --- a/lib/reference/keywordSets.js +++ b/lib/reference/keywordSets.js @@ -679,6 +679,42 @@ keywordSets.nonStandardHtmlTags = new Set([ 'xmp', ]); +// extracted from https://developer.mozilla.org/en-US/docs/Web/SVG/Element +keywordSets.validMixedCaseSvgElements = new Set([ + 'animateMotion', + 'animateTransform', + 'clipPath', + 'feBlend', + 'feColorMatrix', + 'feComponentTransfer', + 'feComposite', + 'feConvolveMatrix', + 'feDiffuseLighting', + 'feDisplacementMap', + 'feDistantLight', + 'feDropShadow', + 'feFlood', + 'feFuncA', + 'feFuncB', + 'feFuncG', + 'feFuncR', + 'feGaussianBlur', + 'feImage', + 'feMerge', + 'feMergeNode', + 'feMorphology', + 'feOffset', + 'fePointLight', + 'feSpecularLighting', + 'feSpotLight', + 'feTile', + 'feTurbulence', + 'foreignObject', + 'linearGradient', + 'radialGradient', + 'textPath', +]); + /** * @param {(string[] | Set)[]} args */ diff --git a/lib/rules/selector-type-case/__tests__/index.js b/lib/rules/selector-type-case/__tests__/index.js index ae9287a531..cfe7993ab4 100644 --- a/lib/rules/selector-type-case/__tests__/index.js +++ b/lib/rules/selector-type-case/__tests__/index.js @@ -95,6 +95,14 @@ testRule({ code: 'a /*comments */\n b {}', description: 'comments in the selector', }, + { + code: 'foreignObject {}', + description: 'valid mixed-case svg elements', + }, + { + code: 'html textPath { fill: red; }', + description: 'valid mixed-case svg elements', + }, ], reject: [ diff --git a/lib/rules/selector-type-case/index.js b/lib/rules/selector-type-case/index.js index ca4d7d09ca..9f432b4a19 100644 --- a/lib/rules/selector-type-case/index.js +++ b/lib/rules/selector-type-case/index.js @@ -11,6 +11,7 @@ const report = require('../../utils/report'); const ruleMessages = require('../../utils/ruleMessages'); const validateOptions = require('../../utils/validateOptions'); const { isString } = require('../../utils/validateTypes'); +const keywordSets = require('../../reference/keywordSets'); const ruleName = 'selector-type-case'; @@ -59,6 +60,10 @@ function rule(expectation, options, context) { return; } + if (keywordSets.validMixedCaseSvgElements.has(tag.value)) { + return; + } + if (optionsMatches(options, 'ignoreTypes', tag.value)) { return; } From e0e363bf1ce8d1b3e25be3686ff9e069ee98a96d Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Sun, 14 Nov 2021 16:44:00 +0000 Subject: [PATCH 2/2] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index cdf585c505..44fb258e98 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ node_modules .coverage .eslintcache yarn.lock -.idea