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

烈酒焚心 提交于 2020-05-25 05:45:05

问题


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?

回答1:


Just use pair of lines:

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

// ... your code here with unused vars...

/* eslint-enable no-unused-vars */



回答2:


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
}



回答3:


One more option...

function doStuff({
  // eslint-disable-next-line no-unused-vars
  unused,
  usedA,
  usedB
}) {



回答4:


For typescript eslint users just add this at the end of line you wish to ignore:

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


来源:https://stackoverflow.com/questions/46284405/how-can-i-use-eslint-no-unused-vars-for-a-block-of-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!