2

We recently updated several NPM packages and other parts of our React application, and now no-unused-vars is throwing an error rather than a warning.

enter image description here

One of the updates to our application was updating from babel-eslist to @babel/eslint-parser in our package.json (now have "@babel/eslint-parser": "^7.18.2"), and updating the parser in our .eslintrc accordingly.

// "parser": "babel-eslint", // 
"parser": "@babel/eslint-parser",

Another potentially-relevant update is that we updated react-scripts to the latest version "react-scripts": "^5.0.1". Is it possible to have no-unused-vars return warnings again, rather than errors?

We have the following rule for no-unused-vars

"rules": {
  ...
  "no-unused-vars": 2, // disallow declaration of variables that are not used in the code
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Canovice
  • 9,012
  • 22
  • 93
  • 211
  • 1
    Did you try configuring this like any other ESLint rule? What _else_ is in your `.eslintrc`? – jonrsharpe May 29 '22 at 18:51
  • We did not make any other changes to our `.eslintrc` other than changing the parser after installing @babel/eslint-parser. Perhaps a rule needs to be added? – Canovice May 29 '22 at 18:52
  • 1
    If you're not happy with your current ESLint configuration, changing it is probably worth a try at least! – jonrsharpe May 29 '22 at 18:57
  • Thanks @jonrsharpe. Zero'ing in on our eslist file. I just updated the question with our eslint rule for this. We haven't changed our eslist rule for `no-unused-vars` so confused why it is now throwing an error rather than a warning. – Canovice May 29 '22 at 18:58
  • `2` is explicitly the error level (I'd recommend using the string rather than number option to make this more obvious, see https://eslint.org/docs/user-guide/configuring/rules#configuring-rules). I don't know why you were only getting warnings before. – jonrsharpe May 29 '22 at 19:00
  • We were using `babel-eslist` before rather than `@babel/eslint-parser`, perhaps the numbers correspond with different levels? – Canovice May 29 '22 at 19:11
  • 1
    Changing the parser (not even changing, really, just a newer version of the same one) wouldn't change any of the configuration of the rules. You _explicitly_ had it at error, as far as what you've shown us says. – jonrsharpe May 29 '22 at 19:18

0 Answers0