Skip to content

Commit

Permalink
[Fix] jsx-uses-vars: ignore namespaces
Browse files Browse the repository at this point in the history
JSX namespaces are transpiled into strings, not identifiers.
  • Loading branch information
remcohaszing authored and ljharb committed May 11, 2021
1 parent 89ba8c5 commit f864ac1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,13 +11,15 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

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

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

[#2985]: https://github.com/yannickcr/eslint-plugin-react/pull/2985
[#2982]: https://github.com/yannickcr/eslint-plugin-react/pull/2982
[#2980]: https://github.com/yannickcr/eslint-plugin-react/pull/2980
[#2977]: https://github.com/yannickcr/eslint-plugin-react/pull/2977
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/jsx-uses-vars.js
Expand Up @@ -26,10 +26,11 @@ module.exports = {
return {
JSXOpeningElement(node) {
let name;
if (node.name.namespace && node.name.namespace.name) {
if (node.name.namespace) {
// <Foo:Bar>
name = node.name.namespace.name;
} else if (node.name.name) {
return;
}
if (node.name.name) {
// <Foo>
name = node.name.name;
} else if (node.name.object) {
Expand Down
8 changes: 1 addition & 7 deletions tests/lib/rules/jsx-uses-vars.js
Expand Up @@ -79,12 +79,6 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
var App;
<App.Hello />
`
}, {
code: `
/* eslint jsx-uses-vars: 1 */
var App;
<App:Hello />
`
}, {
code: `
/* eslint jsx-uses-vars: 1 */
Expand Down Expand Up @@ -143,7 +137,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, {
var Hello;
React.render(<App:Hello/>);
`,
errors: [{message: '\'Hello\' is defined but never used.'}]
errors: [{message: '\'App\' is defined but never used.'}, {message: '\'Hello\' is defined but never used.'}]
}, {
code: `
/* eslint jsx-uses-vars: 1 */
Expand Down

0 comments on commit f864ac1

Please sign in to comment.