Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use ESLint no-unused-vars for a block of code?

I need to disable some variable checks in ESLint.

Currently, I am using this code, but am not getting the desired result:

/* eslint no-unused-vars: ["error", { "caughtErrorsIgnorePattern": "Hey" }] */ export type Hey = {   a: string,   b: object } 

Two questions:

  • Is there a variant which can enable no-unused-vars for a block of code?

Something like...

/* eslint rule disable"*/  // I want to place my block of code, here  /* eslint rule disable"*/ 
  • Or could I make Hey a global variable so that it can be ignored everywhere?
like image 514
Radex Avatar asked Sep 18 '17 16:09

Radex


People also ask

Why are there no unused variables?

Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.

How do I turn off rule ESLint?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

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.


2 Answers

Just use pair of lines:

/* eslint-disable no-unused-vars */  // ... your code here with unused vars...  /* eslint-enable no-unused-vars */ 
like image 135
Ville Venäläinen Avatar answered Oct 02 '22 14:10

Ville Venäläinen


Alternatively, you can disable the rule for one line:

// Based on your Typescript example  export type Hey = { // eslint-disable-line no-unused-vars   a: string,   b: object } 
like image 43
zdolny Avatar answered Oct 02 '22 14:10

zdolny