0
votes

I've setup eslint & eslint-plugin-react.

When I run ESLint, the linter returns no-unused-vars .

I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas?

Line 5:11: 'x' is assigned a value but never used no-unused-vars

Example:

Please help me


Inside a file Component

import React,{ Component } from 'react';
class Item extends Component{
   render () {
       const x = 1;
       return (
         <div>test</div>
       );
    }
};

export default Item;

Inside a file .eslintrc.json

{
"env": {
    "browser": true,
    "es6": true
},
"extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "react-app","prettier"
],
"settings": {
  "react": {
    "createClass": "createReactClass"
    "pragma": "React",
    "version": "detect",
    "flowVersion": "0.53"
  },
  "propWrapperFunctions": [
      "forbidExtraProps",
      {"property": "freeze", "object": "Object"},
      {"property": "myFavoriteWrapper"}
  ],
  "linkComponents": [
    "Hyperlink",
    {"name": "Link", "linkAttribute": "to"}
  ]
},
"parserOptions": {
    "ecmaVersion": 2018,
    "ecmaFeatures": {
      "jsx": true
    }
},
"plugins": [
    "react","prettier"
],
"rules": {
  "react/jsx-uses-react": "error",
  "react/jsx-uses-vars": "error",
  "no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
}

}

1
const x = 1; and you never use x. Why do you think that the assignment would be used?VLAZ
this happen because you are defining x but not use it.So, just remove itPrakash Karena
Welcome to SO! Please note that it is appreciated to keep the provided code as explicit as neccessary, but as short as possible. You might want to have a look at stackoverflow.com/help/minimal-reproducible-example for some inspiration.Twonky

1 Answers

2
votes

ESLint lint behavior is right. You've declared x but don't use in your JSX. It should disappear if use it:)

import React,{ Component } from 'react';
class Item extends Component{
   render () {
       const x = 1;
       return (
         <div>test {x}</div>
       );
    }
};

export default Item;