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 false positives for SVG type selectors in selector-type-case (#5712) #5717

Merged
merged 2 commits into from Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ node_modules
.coverage
.eslintcache
yarn.lock
.idea
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