Skip to content

Commit 0b0e4fb

Browse files
committed
Add SVG attributes support to no-unknown-property (fixes #318)
1 parent b437680 commit 0b0e4fb

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/rules/no-unknown-property.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var DOM_ATTRIBUTE_NAMES = {
1818
};
1919

2020
var DOM_PROPERTY_NAMES = [
21+
// Standard
2122
'acceptCharset', 'accessKey', 'allowFullScreen', 'allowTransparency', 'autoComplete', 'autoFocus', 'autoPlay',
2223
'cellPadding', 'cellSpacing', 'charSet', 'classID', 'className', 'colSpan', 'contentEditable', 'contextMenu',
2324
'crossOrigin', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
@@ -28,7 +29,20 @@ var DOM_PROPERTY_NAMES = [
2829
'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onPaste', 'onScroll', 'onSubmit', 'onTouchCancel',
2930
'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onWheel',
3031
'radioGroup', 'readOnly', 'rowSpan', 'spellCheck', 'srcDoc', 'srcSet', 'tabIndex', 'useMap',
31-
'itemProp', 'itemScope', 'itemType', 'itemRef', 'itemID'
32+
// Non standard
33+
'autoCapitalize', 'autoCorrect',
34+
'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'
3246
];
3347

3448
// ------------------------------------------------------------------------------
@@ -69,7 +83,7 @@ function getStandardName(name) {
6983
i = index;
7084
return element.toLowerCase() === name;
7185
});
72-
return found ? DOM_PROPERTY_NAMES[i] : null;
86+
return found ? DOM_PROPERTY_NAMES[i].replace(':', '') : null;
7387
}
7488

7589
// ------------------------------------------------------------------------------
@@ -81,12 +95,13 @@ module.exports = function(context) {
8195
return {
8296

8397
JSXAttribute: function(node) {
84-
var standardName = getStandardName(node.name.name);
98+
var name = context.getSource(node.name);
99+
var standardName = getStandardName(name);
85100
if (!isTagName(node) || !standardName) {
86101
return;
87102
}
88103
context.report(node, UNKNOWN_MESSAGE, {
89-
name: node.name.name,
104+
name: name,
90105
standardName: standardName
91106
});
92107
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ruleTester.run('no-unknown-property', rule, {
2323
{code: '<App for="bar" />;', ecmaFeatures: {jsx: true}},
2424
{code: '<App accept-charset="bar" />;', ecmaFeatures: {jsx: true}},
2525
{code: '<App http-equiv="bar" />;', ecmaFeatures: {jsx: true}},
26+
{code: '<App xlink:href="bar" />;', ecmaFeatures: {jsx: true}},
2627
{code: '<div className="bar"></div>;', ecmaFeatures: {jsx: true}},
2728
{code: '<div data-foo="bar"></div>;', ecmaFeatures: {jsx: true}},
2829
{code: '<div class="foo" is="my-elem"></div>;', ecmaFeatures: {jsx: true}},
@@ -56,6 +57,10 @@ ruleTester.run('no-unknown-property', rule, {
5657
}, {
5758
code: '<div onmousedown="bar"></div>;',
5859
errors: [{message: 'Unknown property \'onmousedown\' found, use \'onMouseDown\' instead'}],
59-
ecmaFeatures: {jsx: true}}
60-
]
60+
ecmaFeatures: {jsx: true}
61+
}, {
62+
code: '<use xlink:href="bar" />;',
63+
errors: [{message: 'Unknown property \'xlink:href\' found, use \'xlinkHref\' instead'}],
64+
ecmaFeatures: {jsx: true}
65+
}]
6166
});

0 commit comments

Comments
 (0)