question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-unused-vars doesn't recognize the use of imported modules as jsx components

See original GitHub issue

Enviroment:

  • 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:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
anthonybrowncommented, May 5, 2017

so it seems that using the extends: ['plugin:react/recommended'] the unused-vars error goes away.

3reactions
iliran11commented, Mar 11, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found