Skip to content

Commit

Permalink
[Fix] jsx-uses-vars: ignore lowercase tag names
Browse files Browse the repository at this point in the history
  • Loading branch information
alanorozco authored and ljharb committed Sep 8, 2021
1 parent 577cb64 commit 5340e9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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)) {
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

0 comments on commit 5340e9d

Please sign in to comment.