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] jsx-uses-vars ignores lowercase tag names #3070

Merged
merged 1 commit into from Sep 9, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,7 +10,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`prop-types`], `propTypes`: handle implicit `children` prop in react's generic types ([#3064][] @vedadeepta)
* [`display-name`]: fix arrow function returning result of function call with JSX arguments being interpreted as component ([#3065][] @danielfinke)
* [`jsx-no-target-blank`]: avoid crash on attr-only href ([#3066][] @ljharb @gaz77a)
* [`jsx-uses-vars`]: ignore lowercase tag names ([#3070][] @alanorozco)

[#3070]: https://github.com/yannickcr/eslint-plugin-react/pull/3070
[#3066]: https://github.com/yannickcr/eslint-plugin-react/issue/3066
[#3065]: https://github.com/yannickcr/eslint-plugin-react/pull/3065
[#3064]: https://github.com/yannickcr/eslint-plugin-react/pull/3064
Expand Down
7 changes: 7 additions & 0 deletions lib/rules/jsx-uses-vars.js
Expand Up @@ -11,6 +11,9 @@ const docsUrl = require('../util/docsUrl');
// Rule Definition
// ------------------------------------------------------------------------------

const isTagNameRe = /^[a-z]/;
const isTagName = (name) => isTagNameRe.test(name);

module.exports = {
meta: {
docs: {
Expand All @@ -33,6 +36,10 @@ module.exports = {
if (node.name.name) {
// <Foo>
name = node.name.name;
// Exclude lowercase tag names like <div>
if (isTagName(name)) {
ljharb marked this conversation as resolved.
Show resolved Hide resolved
return;
}
} else if (node.name.object) {
// <Foo...Bar>
let parent = node.name.object;
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/jsx-uses-vars.js
Expand Up @@ -116,6 +116,18 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
};
foo()
`
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var object;
React.render(<object.Tag />);
`
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var object;
React.render(<object.tag />);
`
}
],
invalid: [
Expand Down Expand Up @@ -196,6 +208,13 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
line: 3
}],
parser: parsers.BABEL_ESLINT
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var lowercase;
React.render(<lowercase />);
`,
errors: [{message: '\'lowercase\' is defined but never used.'}]
}
]
});
Expand Down