Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript eslint disable no-unused-vars

Tags:

I am working on a Typescript React project and I usually put placeholder variables into the code so everything is laid out until I get to implementing everything. This leads to a bunch of eslint no-unused-vars errors and makes finding real errors a challage.

How can I disable this globally until I am ready for it? I used create-react-app my-app --typescript and don't want to eject the project but not sure how to disable this warning.

I noticed there is a eslintConfig section in the package.json so I tried to turn off the error there but it doesn't seem to work, is there a command I need to run after editing the package.json or is my syntax incorrect?

"eslintConfig": {     "extends": "react-app",     "rules": {       "no-unused-vars": "off"     }  }, 

Update


(removed tsconfig.json reference)

I updated my package.json and keep getting the errors.

"eslintConfig": {     "extends": "react-app",     "rules": {       "@typescript-eslint/no-unused-vars": "off"     }   }, 

I tried moving the rules into a .eslintrc.json file in the root of the project and still doesn't seem to turn this off.

The only thing that seems to work is putting // eslint-disable-line @typescript-eslint/no-unused-vars after the variable.

like image 353
Andy Braham Avatar asked Sep 25 '19 12:09

Andy Braham


People also ask

How do I disable TypeScript ESLint?

If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.

How do you remove unused variables from ESLint?

To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin. Now, when you run ESLint, you should see error lines saying error '<imported-var>' is defined but never used unused-imports/no-unused-imports for the files where you have unused imports.

How do I disable ESLint for multiple lines?

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console.


1 Answers

I think there is some confusion.

Both the question and the only answer suggest putting a rules section in the tsconfig.json. This is something I've never heard of, and it is not mentioned in the docs or in the official schema.

Also, the question is about disabling the rule in eslint so the rule change should go in the .eslintrc.json file (or the eslintConfig section in the package.json as considered in the question).

But this is typescript and typescript-eslint so the rule should be:

> "@typescript-eslint/no-unused-vars" : "off" 

And the hacky solution proposed in an answer that someone linked to needs to be changed to (note that answer is about eslint for js, not ts).

/* eslint-disable @typescript-eslint/no-unused-vars */ 

And those solutions work for me using...

+-- [email protected]   +-- @typescript-eslint/[email protected]   +-- @typescript-eslint/[email protected]   
like image 174
Tom Avatar answered Sep 17 '22 13:09

Tom