javascript 如何将 ESLint no-unused-vars 用于代码块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46284405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use ESLint no-unused-vars for a block of code?
提问by Radex
I need to disable some variable checks in ESLint.
我需要在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-varsfor a block of code?
- 是否有可以启用
no-unused-vars代码块的变体?
Something like...
就像是...
/* eslint rule disable"*/
// I want to place my block of code, here
/* eslint rule disable"*/
- Or could I make
Heya global variable so that it can be ignored everywhere?
- 或者我可以创建
Hey一个全局变量以便在任何地方都可以忽略它吗?
回答by Ville Ven?l?inen
Just use pair of lines:
只需使用一对线:
/* eslint-disable no-unused-vars */
// ... your code here with unused vars...
/* eslint-enable no-unused-vars */
回答by zdolny
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
}
回答by Martin
One more option...
还有一种选择……
function doStuff({
// eslint-disable-next-line no-unused-vars
unused,
usedA,
usedB
}) {
回答by Tim J
For typescript eslint users just add this at the end of line you wish to ignore:
对于打字稿 eslint 用户,只需在您希望忽略的行尾添加:
// eslint-disable-line @typescript-eslint/no-unused-vars

