Reputation: 890
I'm using webpack with React and Eslint, I have set the extends on Eslint, however, it still says 'React' is defined but never used.eslintno-unused-vars
This is my .eslintrc file:
{
"parser": "babel-eslint",
"extends": ["eslint:recommended", "plugin:react/recommended", "airbnb", "prettier"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2015
},
"env": {
"browser": true,
"node": true,
"jest": true,
"commonjs": true
},
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"linebreak-style": "off",
"no-undef": "off",
"no-debugger": "off",
"no-alert": "off",
"indent": ["error", 4],
"quotes": "off",
"no-console": "off"
}
}
React version is ^17.0.1
babel-eslint is ^10.1.0
eslint is ^7.14.0
eslint-plugin-react is ^7.21.5
Upvotes: 0
Views: 225
Reputation: 196
Looks like it has to do with actual JSX in the file
Your config worked fine on a file that actually contains valid JSX:
// App.jsx
import React from 'react'; //
const App = () => {
return <div />; // JSX
}
export default App
But if no JSX is found in the file it throws the error you described:
// App.jsx
import React from 'react'; // 'React' is defined but never used
const App = () => {
return 1; // no JSX
}
export default App
Upvotes: 1