Skip to content

Commit 8ada88f

Browse files
committed
Fix SVG attributes support for no-unknown-property (fixes #338)
1 parent 012e55f commit 8ada88f

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

lib/rules/no-unknown-property.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,36 @@
1111
var UNKNOWN_MESSAGE = 'Unknown property \'{{name}}\' found, use \'{{standardName}}\' instead';
1212

1313
var DOM_ATTRIBUTE_NAMES = {
14+
// Standard
1415
'accept-charset': 'acceptCharset',
1516
class: 'className',
1617
for: 'htmlFor',
17-
'http-equiv': 'httpEquiv'
18+
'http-equiv': 'httpEquiv',
19+
// SVG
20+
'clip-path': 'clipPath',
21+
'fill-opacity': 'fillOpacity',
22+
'font-family': 'fontFamily',
23+
'font-size': 'fontSize',
24+
'marker-end': 'markerEnd',
25+
'marker-mid': 'markerMid',
26+
'marker-start': 'markerStart',
27+
'stop-color': 'stopColor',
28+
'stop-opacity': 'stopOpacity',
29+
'stroke-dasharray': 'strokeDasharray',
30+
'stroke-linecap': 'strokeLinecap',
31+
'stroke-opacity': 'strokeOpacity',
32+
'stroke-width': 'strokeWidth',
33+
'text-anchor': 'textAnchor',
34+
'xlink:actuate': 'xlinkActuate',
35+
'xlink:arcrole': 'xlinkArcrole',
36+
'xlink:href': 'xlinkHref',
37+
'xlink:role': 'xlinkRole',
38+
'xlink:show': 'xlinkShow',
39+
'xlink:title': 'xlinkTitle',
40+
'xlink:type': 'xlinkType',
41+
'xml:base': 'xmlBase',
42+
'xml:lang': 'xmlLang',
43+
'xml:space': 'xmlSpace'
1844
};
1945

2046
var DOM_PROPERTY_NAMES = [
@@ -32,17 +58,7 @@ var DOM_PROPERTY_NAMES = [
3258
// Non standard
3359
'autoCapitalize', 'autoCorrect',
3460
'autoSave',
35-
'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemID',
36-
// SVG
37-
'clipPath', 'cx', 'cy', 'd', 'dx', 'dy', 'fill', 'fillOpacity', 'fontFamily',
38-
'fontSize', 'fx', 'fy', 'gradientTransform', 'gradientUnits', 'markerEnd',
39-
'markerMid', 'markerStart', 'offset', 'opacity', 'patternContentUnits',
40-
'patternUnits', 'points', 'preserveAspectRatio', 'r', 'rx', 'ry', 'spreadMethod',
41-
'stopColor', 'stopOpacity', 'stroke', 'strokeDasharray', 'strokeLinecap',
42-
'strokeOpacity', 'strokeWidth', 'textAnchor', 'transform', 'version',
43-
'viewBox', 'x1', 'x2', 'x', 'y1', 'y2', 'y',
44-
'xlink:Actuate', 'xlink:Arcrole', 'xlink:Href', 'xlink:Role', 'xlink:Show', 'xlink:Title', 'xlink:Type',
45-
'xml:Base', 'xml:Lang', 'xml:Space'
61+
'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemID'
4662
];
4763

4864
// ------------------------------------------------------------------------------
@@ -83,7 +99,7 @@ function getStandardName(name) {
8399
i = index;
84100
return element.toLowerCase() === name;
85101
});
86-
return found ? DOM_PROPERTY_NAMES[i].replace(':', '') : null;
102+
return found ? DOM_PROPERTY_NAMES[i] : null;
87103
}
88104

89105
// ------------------------------------------------------------------------------

tests/lib/rules/no-unknown-property.js

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ruleTester.run('no-unknown-property', rule, {
2424
{code: '<App accept-charset="bar" />;', ecmaFeatures: {jsx: true}},
2525
{code: '<App http-equiv="bar" />;', ecmaFeatures: {jsx: true}},
2626
{code: '<App xlink:href="bar" />;', ecmaFeatures: {jsx: true}},
27+
{code: '<App clip-path="bar" />;', ecmaFeatures: {jsx: true}},
2728
{code: '<div className="bar"></div>;', ecmaFeatures: {jsx: true}},
2829
{code: '<div data-foo="bar"></div>;', ecmaFeatures: {jsx: true}},
2930
{code: '<div class="foo" is="my-elem"></div>;', ecmaFeatures: {jsx: true}},
@@ -62,5 +63,9 @@ ruleTester.run('no-unknown-property', rule, {
6263
code: '<use xlink:href="bar" />;',
6364
errors: [{message: 'Unknown property \'xlink:href\' found, use \'xlinkHref\' instead'}],
6465
ecmaFeatures: {jsx: true}
66+
}, {
67+
code: '<rect clip-path="bar" />;',
68+
errors: [{message: 'Unknown property \'clip-path\' found, use \'clipPath\' instead'}],
69+
ecmaFeatures: {jsx: true}
6570
}]
6671
});

0 commit comments

Comments
 (0)