Skip to content

Commit 5340e9d

Browse files
alanorozcoljharb
authored andcommitted
[Fix] jsx-uses-vars: ignore lowercase tag names
Fixes eslint/eslint#15040
1 parent 577cb64 commit 5340e9d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1010
* [`prop-types`], `propTypes`: handle implicit `children` prop in react's generic types ([#3064][] @vedadeepta)
1111
* [`display-name`]: fix arrow function returning result of function call with JSX arguments being interpreted as component ([#3065][] @danielfinke)
1212
* [`jsx-no-target-blank`]: avoid crash on attr-only href ([#3066][] @ljharb @gaz77a)
13+
* [`jsx-uses-vars`]: ignore lowercase tag names ([#3070][] @alanorozco)
1314

15+
[#3070]: https://github.com/yannickcr/eslint-plugin-react/pull/3070
1416
[#3066]: https://github.com/yannickcr/eslint-plugin-react/issue/3066
1517
[#3065]: https://github.com/yannickcr/eslint-plugin-react/pull/3065
1618
[#3064]: https://github.com/yannickcr/eslint-plugin-react/pull/3064

lib/rules/jsx-uses-vars.js

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const docsUrl = require('../util/docsUrl');
1111
// Rule Definition
1212
// ------------------------------------------------------------------------------
1313

14+
const isTagNameRe = /^[a-z]/;
15+
const isTagName = (name) => isTagNameRe.test(name);
16+
1417
module.exports = {
1518
meta: {
1619
docs: {
@@ -33,6 +36,10 @@ module.exports = {
3336
if (node.name.name) {
3437
// <Foo>
3538
name = node.name.name;
39+
// Exclude lowercase tag names like <div>
40+
if (isTagName(name)) {
41+
return;
42+
}
3643
} else if (node.name.object) {
3744
// <Foo...Bar>
3845
let parent = node.name.object;

tests/lib/rules/jsx-uses-vars.js

+19
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
116116
};
117117
foo()
118118
`
119+
}, {
120+
code: `
121+
/* eslint jsx-uses-vars: 1 */
122+
var object;
123+
React.render(<object.Tag />);
124+
`
125+
}, {
126+
code: `
127+
/* eslint jsx-uses-vars: 1 */
128+
var object;
129+
React.render(<object.tag />);
130+
`
119131
}
120132
],
121133
invalid: [
@@ -196,6 +208,13 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
196208
line: 3
197209
}],
198210
parser: parsers.BABEL_ESLINT
211+
}, {
212+
code: `
213+
/* eslint jsx-uses-vars: 1 */
214+
var lowercase;
215+
React.render(<lowercase />);
216+
`,
217+
errors: [{message: '\'lowercase\' is defined but never used.'}]
199218
}
200219
]
201220
});

0 commit comments

Comments
 (0)