no-unused-vars doesn't recognize the use of imported modules as jsx components
See original GitHub issueEnviroment:
- ESLint Version: v3.17.1
- Node Version: v6.9.5
- npm Version: 3.10.10
- Visual Studio Code: 1.10.2
- ESLint Extension for Visual Studio Code: 1.2.7
Parser for building the project:
- Babel, using this .babelrc:
{
"presets": ["react", "es2015", "stage-1"]
}
full configuration:
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
What did you do? Please include the actual source code causing the issue.
App
and Provider
are giving error for no-unused-vars
but they are used inside the jsx as components.
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux'; // gives no-unused-vars error
import { createStore, applyMiddleware } from 'redux';
import App from './components/app'; //// gives no-unused-vars error
import reducers from './reducers';
const createStoreWithMiddleware = applyMiddleware()(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.container'));
What did you expect to happen?
ESLint should have recognized that App and Provider vars are used inside the jsx, and consider them as used vars.
raw output from ESLint.
file: 'file:///c%3A/projects/weather-redux/src/index.js'
severity: 'Error'
message: ''Provider' is defined but never used. (no-unused-vars)'
at: '2,10'
source: 'eslint'
file: 'file:///c%3A/projects/weather-redux/src/index.js'
severity: 'Error'
message: ''App' is defined but never used. (no-unused-vars)'
at: '5,8'
source: 'eslint'
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top Results From Across the Web
ESLint with React gives `no-unused-vars` errors
I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas? Example: app.js import React, { Component } from 'react...
Read more >eslint-plugin-unused-imports - npm
Find and remove unused es6 module imports. It works by splitting up the no-unused-vars rule depending on it being an import statement in...
Read more >Common React TypeScript ESLint / Lint Errors & Warning ...
The lint message: Component should be written as a pure function (react ... use React.MouseEvent or import the MouseEvent typing from the React...
Read more >React Top-Level API
If you use ES6 with npm, you can write import React from 'react' . If you use ES5 with ... Component doesn't implement...
Read more >Assigned a Value but Never Used | React JS Debugging
In react component I want to display a name but I want to read it from the app state. This name will not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
so it seems that using the
extends: ['plugin:react/recommended']
theunused-vars
error goes away.thanks … i created those settings via the wizard. eslint --init
would make sense to add it to the wizard no? 😃 it’s a very common scenario