Skip to content

Commit

Permalink
[Fix]no-unknown-property: fix case like <Foo.bar>
Browse files Browse the repository at this point in the history
Fixes #2204
  • Loading branch information
golopot authored and ljharb committed Mar 19, 2019
1 parent 21b7edd commit 6bb1604
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/rules/no-unknown-property.js
Expand Up @@ -167,6 +167,20 @@ function getTagName(node) {
return null;
}

/**
* Test wether the tag name for the JSXAttribute is
* something like <Foo.bar />
* @param {JSXAttribute} node - JSXAttribute being tested.
* @returns {Boolean} result
*/
function tagNameHasDot(node) {
return !!(
node.parent &&
node.parent.name &&
node.parent.name.type === 'JSXMemberExpression'
);
}

/**
* Get the standard name of the attribute.
* @param {String} name - Name of the attribute.
Expand Down Expand Up @@ -231,6 +245,11 @@ module.exports = {
return;
}

// Ignore tags like <Foo.bar />
if (tagNameHasDot(node)) {
return;
}

const tagName = getTagName(node);
const allowedTags = ATTRIBUTE_TAGS_MAP[name];
if (tagName && allowedTags && /[^A-Z]/.test(tagName.charAt(0)) && allowedTags.indexOf(tagName) === -1) {
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-unknown-property.js
Expand Up @@ -29,6 +29,7 @@ ruleTester.run('no-unknown-property', rule, {
valid: [
{code: '<App class="bar" />;'},
{code: '<App for="bar" />;'},
{code: '<Foo.bar for="bar" />;'},
{code: '<App accept-charset="bar" />;'},
{code: '<meta charset="utf-8" />;'},
{code: '<meta charSet="utf-8" />;'},
Expand Down

0 comments on commit 6bb1604

Please sign in to comment.