Skip to content

Commit 6bb1604

Browse files
golopotljharb
authored andcommitted
[Fix]no-unknown-property: fix case like <Foo.bar>
Fixes jsx-eslint#2204
1 parent 21b7edd commit 6bb1604

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/rules/no-unknown-property.js

+19
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ function getTagName(node) {
167167
return null;
168168
}
169169

170+
/**
171+
* Test wether the tag name for the JSXAttribute is
172+
* something like <Foo.bar />
173+
* @param {JSXAttribute} node - JSXAttribute being tested.
174+
* @returns {Boolean} result
175+
*/
176+
function tagNameHasDot(node) {
177+
return !!(
178+
node.parent &&
179+
node.parent.name &&
180+
node.parent.name.type === 'JSXMemberExpression'
181+
);
182+
}
183+
170184
/**
171185
* Get the standard name of the attribute.
172186
* @param {String} name - Name of the attribute.
@@ -231,6 +245,11 @@ module.exports = {
231245
return;
232246
}
233247

248+
// Ignore tags like <Foo.bar />
249+
if (tagNameHasDot(node)) {
250+
return;
251+
}
252+
234253
const tagName = getTagName(node);
235254
const allowedTags = ATTRIBUTE_TAGS_MAP[name];
236255
if (tagName && allowedTags && /[^A-Z]/.test(tagName.charAt(0)) && allowedTags.indexOf(tagName) === -1) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ruleTester.run('no-unknown-property', rule, {
2929
valid: [
3030
{code: '<App class="bar" />;'},
3131
{code: '<App for="bar" />;'},
32+
{code: '<Foo.bar for="bar" />;'},
3233
{code: '<App accept-charset="bar" />;'},
3334
{code: '<meta charset="utf-8" />;'},
3435
{code: '<meta charSet="utf-8" />;'},

0 commit comments

Comments
 (0)