Skip to content

Commit

Permalink
Fix false positives for SVG type selectors in selector-type-case (#5717)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
  • Loading branch information
hverlin and jeddy3 committed Nov 14, 2021
1 parent abc3795 commit b37ab72
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/reference/keywordSets.js
Expand Up @@ -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<string>)[]} args
*/
Expand Down
8 changes: 8 additions & 0 deletions lib/rules/selector-type-case/__tests__/index.js
Expand Up @@ -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: [
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/selector-type-case/index.js
Expand Up @@ -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';

Expand Down Expand Up @@ -59,6 +60,10 @@ function rule(expectation, options, context) {
return;
}

if (keywordSets.validMixedCaseSvgElements.has(tag.value)) {
return;
}

if (optionsMatches(options, 'ignoreTypes', tag.value)) {
return;
}
Expand Down

0 comments on commit b37ab72

Please sign in to comment.