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]no-unknown-property: fix case like <Foo.bar> #2207

Merged
merged 1 commit into from Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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