Skip to content

Commit f864ac1

Browse files
remcohaszingljharb
authored andcommitted
[Fix] jsx-uses-vars: ignore namespaces
JSX namespaces are transpiled into strings, not identifiers.
1 parent 89ba8c5 commit f864ac1

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1111

1212
### Fixed
1313
* [`jsx-handler-names`]: properly substitute value into message ([#2975][] @G-Rath)
14+
* [`jsx-uses-vars`]: ignore namespaces ([#2985][] @remcohaszing)
1415

1516
### Changed
1617
* [Docs] [`jsx-newline`]: Fix minor spelling error on rule name ([#2974][] @DennisSkoko)
1718
* [Refactor] [`void-dom-elements-no-children`]: improve performance
1819
* [readme] fix missing trailing commas ([#2980][] @sugardon)
1920
* [readme] fix broken anchor link ([#2982][] @vzvu3k6k)
2021

22+
[#2985]: https://github.com/yannickcr/eslint-plugin-react/pull/2985
2123
[#2982]: https://github.com/yannickcr/eslint-plugin-react/pull/2982
2224
[#2980]: https://github.com/yannickcr/eslint-plugin-react/pull/2980
2325
[#2977]: https://github.com/yannickcr/eslint-plugin-react/pull/2977

lib/rules/jsx-uses-vars.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ module.exports = {
2626
return {
2727
JSXOpeningElement(node) {
2828
let name;
29-
if (node.name.namespace && node.name.namespace.name) {
29+
if (node.name.namespace) {
3030
// <Foo:Bar>
31-
name = node.name.namespace.name;
32-
} else if (node.name.name) {
31+
return;
32+
}
33+
if (node.name.name) {
3334
// <Foo>
3435
name = node.name.name;
3536
} else if (node.name.object) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
7979
var App;
8080
<App.Hello />
8181
`
82-
}, {
83-
code: `
84-
/* eslint jsx-uses-vars: 1 */
85-
var App;
86-
<App:Hello />
87-
`
8882
}, {
8983
code: `
9084
/* eslint jsx-uses-vars: 1 */
@@ -143,7 +137,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
143137
var Hello;
144138
React.render(<App:Hello/>);
145139
`,
146-
errors: [{message: '\'Hello\' is defined but never used.'}]
140+
errors: [{message: '\'App\' is defined but never used.'}, {message: '\'Hello\' is defined but never used.'}]
147141
}, {
148142
code: `
149143
/* eslint jsx-uses-vars: 1 */

0 commit comments

Comments
 (0)