Skip to content

Commit 0b94fd6

Browse files
committed
Merge pull request #308 from zertosh/nup-custom-el
Fix no-unknown-property to not check custom elements
2 parents 218e9fc + 1ec1b18 commit 0b94fd6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/rules/no-unknown-property.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ var DOM_PROPERTY_NAMES = [
3636
// ------------------------------------------------------------------------------
3737

3838
/**
39-
* Checks if a node name match the JSX tag convention.
40-
* @param {String} name - Name of the node to check.
39+
* Checks if a node matches the JSX tag convention.
40+
* @param {Object} node - JSX element being tested.
4141
* @returns {boolean} Whether or not the node name match the JSX tag convention.
4242
*/
43-
var tagConvention = /^[a-z]|\-/;
44-
function isTagName(name) {
45-
return tagConvention.test(name);
43+
var tagConvention = /^[a-z][^-]*$/;
44+
function isTagName(node) {
45+
if (tagConvention.test(node.parent.name.name)) {
46+
// http://www.w3.org/TR/custom-elements/#type-extension-semantics
47+
return !node.parent.attributes.some(function(attrNode) {
48+
return (
49+
attrNode.type === 'JSXAttribute' &&
50+
attrNode.name.type === 'JSXIdentifier' &&
51+
attrNode.name.name === 'is'
52+
);
53+
});
54+
}
55+
return false;
4656
}
4757

4858
/**
@@ -72,7 +82,7 @@ module.exports = function(context) {
7282

7383
JSXAttribute: function(node) {
7484
var standardName = getStandardName(node.name.name);
75-
if (!isTagName(node.parent.name.name) || !standardName) {
85+
if (!isTagName(node) || !standardName) {
7686
return;
7787
}
7888
context.report(node, UNKNOWN_MESSAGE, {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ 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: '<div className="bar"></div>;', ecmaFeatures: {jsx: true}},
27-
{code: '<div data-foo="bar"></div>;', ecmaFeatures: {jsx: true}}
27+
{code: '<div data-foo="bar"></div>;', ecmaFeatures: {jsx: true}},
28+
{code: '<div class="foo" is="my-elem"></div>;', ecmaFeatures: {jsx: true}},
29+
{code: '<div {...this.props} class="foo" is="my-elem"></div>;', ecmaFeatures: {jsx: true}},
30+
{code: '<atom-panel class="foo"></atom-panel>;', ecmaFeatures: {jsx: true}}
2831
],
2932
invalid: [{
3033
code: '<div class="bar"></div>;',

0 commit comments

Comments
 (0)