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

React is defined but never used no-unused-vars #1463

Closed
evserykh opened this issue Oct 4, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@evserykh
Copy link

commented Oct 4, 2017

I have the error 'React' is defined but never used no-unused-vars for *.jsx files with jsx markup. Here is some of my environment:

  1. package.json
"react": "^16.0.0"
"babel-eslint": "^8.0.1"                                                                                                                                                                                  
"eslint": "^4.8.0"                                                                                                                                                                                        
"eslint-config-airbnb": "^15.1.0"                                                                                                                                                 "eslint-import-resolver-webpack": "^0.8.3"                                                                                                                                                                
"eslint-loader": "^1.9.0"                                                                                                                                                                                 
"eslint-plugin-import": "^2.7.0"                                                                                                                                                                          
"eslint-plugin-jsx-a11y": "^5.1.1"                                                                                                                                                                        
"eslint-plugin-react": "^7.4.0"                                                                                                                                                     
  1. .eslintrc.json
{                                                                                                                          
  "env": {                                                                                                                 
    "browser": true                                                                                                        
  },                                                                                                                       
  "extends": [                                                                                                             
    "airbnb",                                                                                                              
    "plugin:react/recommended"                                                                                             
  ],                                                                                                                       
  "parser": "babel-eslint",                                                                                                
  "plugins": [                                                                                                             
    "import",                                                                                                              
    "react",                                                                                                               
    "jsx-a11y"                                                                                                             
  ],                                                                                                                       
  "rules": {                                                                                                               
    "comma-dangle": ["error", "never"],                                                                                    
    "max-len": ["error", 120],                                                                                             
    "no-unused-vars": ["error", { "args": "none" }],                                                                       
    "react/prop-types": "off"                                                                                              
  },                                                                                                                       
  "settings": {                                                                                                            
    "import/resolver": {                                                                                                   
      "webpack": {                                                                                                         
        "config": "config/webpack/development.js"                                                                          
      }                                                                                                                    
    }                                                                                                                      
  }                                                                                                                        
} 

How can I fix it?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Oct 4, 2017

@evserykh

This comment has been minimized.

Copy link
Author

commented Oct 4, 2017

@ljharb I've just tried adding "react/jsx-uses-vars": "error" and "react/jsx-uses-react": "error" rules but it didn't work

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Oct 4, 2017

hmm, assuming npm ls exits zero, that should work (and the recommended config should include those rules anyways)

@evserykh

This comment has been minimized.

Copy link
Author

commented Oct 4, 2017

Oh, sorry, my bad ☹️
I understood what's wrong. As I use React 0.16 I have some draft components like this:

import React from 'react';
const Foo = () => 'Foo';
export default Foo;

The error is quite logical. When I change markup to <div>Foo</div> all works fine

@evserykh evserykh closed this Oct 4, 2017

@ljharb ljharb added the invalid label Oct 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.