[英]eslint: disable warning - `defined but never used` for specific function?
So I have this function:所以我有这个function:
function render(){
// do stuff
}
I do not call that function, because it is called from html as an event function, like:我不称它为 function,因为它是从 html 作为事件 function 调用的,例如:
<textarea id="input" class="input-box" onkeyup="render()"></textarea>
Well eslint
does not see that, so it gives that warning ( render
is defined, but never used).好吧
eslint
没有看到,所以它给出了警告( render
已定义,但从未使用过)。 Is there a way to specify that function is called elsewhere?有没有办法指定 function 在其他地方被调用? Or just mute the warning?
或者只是静音警告?
For example if global variable is used, I can do /* global SomeVar*/
and it will mute warning of not defined variable.例如,如果使用全局变量,我可以执行
/* global SomeVar*/
它将静音未定义变量的警告。 Maybe something similar could be done on functions like in example?也许可以对示例中的功能进行类似的操作?
So I have this function:所以我有这个功能:
function render(){
// do stuff
}
I do not call that function, because it is called from html as an event function, like:我不调用该函数,因为它是从 html 中作为事件函数调用的,例如:
<textarea id="input" class="input-box" onkeyup="render()"></textarea>
Well eslint
does not see that, so it gives that warning ( render
is defined, but never used). eslint
没有看到,所以它给出了警告( render
已定义,但从未使用过)。 Is there a way to specify that function is called elsewhere?有没有办法指定在别处调用该函数? Or just mute the warning?
或者只是静音警告?
For example if global variable is used, I can do /* global SomeVar*/
and it will mute warning of not defined variable.例如,如果使用全局变量,我可以执行
/* global SomeVar*/
并且它将静音未定义变量的警告。 Maybe something similar could be done on functions like in example?也许可以对示例中的函数进行类似的操作?
So I have this function:所以我有这个功能:
function render(){
// do stuff
}
I do not call that function, because it is called from html as an event function, like:我不调用该函数,因为它是从 html 中作为事件函数调用的,例如:
<textarea id="input" class="input-box" onkeyup="render()"></textarea>
Well eslint
does not see that, so it gives that warning ( render
is defined, but never used). eslint
没有看到,所以它给出了警告( render
已定义,但从未使用过)。 Is there a way to specify that function is called elsewhere?有没有办法指定在别处调用该函数? Or just mute the warning?
或者只是静音警告?
For example if global variable is used, I can do /* global SomeVar*/
and it will mute warning of not defined variable.例如,如果使用全局变量,我可以执行
/* global SomeVar*/
并且它将静音未定义变量的警告。 Maybe something similar could be done on functions like in example?也许可以对示例中的函数进行类似的操作?
Just put this rule in.eslintrc.js file, please don't forget to restart serve..把这条规则放在.eslintrc.js 文件中,请不要忘记重启服务..
module.exports = {
rules: {
"no-unused-vars": "off",
},
}
So I have this function:所以我有这个功能:
function render(){
// do stuff
}
I do not call that function, because it is called from html as an event function, like:我不调用该函数,因为它是从 html 中作为事件函数调用的,例如:
<textarea id="input" class="input-box" onkeyup="render()"></textarea>
Well eslint
does not see that, so it gives that warning ( render
is defined, but never used). eslint
没有看到,所以它给出了警告( render
已定义,但从未使用过)。 Is there a way to specify that function is called elsewhere?有没有办法指定在别处调用该函数? Or just mute the warning?
或者只是静音警告?
For example if global variable is used, I can do /* global SomeVar*/
and it will mute warning of not defined variable.例如,如果使用全局变量,我可以执行
/* global SomeVar*/
并且它将静音未定义变量的警告。 Maybe something similar could be done on functions like in example?也许可以对示例中的函数进行类似的操作?
So I have this function:所以我有这个功能:
function render(){
// do stuff
}
I do not call that function, because it is called from html as an event function, like:我不调用该函数,因为它是从 html 中作为事件函数调用的,例如:
<textarea id="input" class="input-box" onkeyup="render()"></textarea>
Well eslint
does not see that, so it gives that warning ( render
is defined, but never used). eslint
没有看到,所以它给出了警告( render
已定义,但从未使用过)。 Is there a way to specify that function is called elsewhere?有没有办法指定在别处调用该函数? Or just mute the warning?
或者只是静音警告?
For example if global variable is used, I can do /* global SomeVar*/
and it will mute warning of not defined variable.例如,如果使用全局变量,我可以执行
/* global SomeVar*/
并且它将静音未定义变量的警告。 Maybe something similar could be done on functions like in example?也许可以对示例中的函数进行类似的操作?
Pretty similar to what Alex K. is proposing, there is also eslint-disable-next-line
.与 Alex K. 的提议非常相似,还有
eslint-disable-next-line
。 I generally prefer that to not make the method definition line of code too long.我通常更喜欢不要让代码的方法定义行太长。 You can use it like this:
你可以像这样使用它:
// eslint-disable-next-line no-unused-vars
function render(){
// do stuff
}
You can add the argsIgnorePattern
option specifies exceptions not to check for usage: arguments whose names match a regexp pattern.您可以添加
argsIgnorePattern
选项指定不检查使用情况的异常:arguments,其名称与正则表达式模式匹配。 For example, variables whose names begin with an underscore.例如,名称以下划线开头的变量。
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]
@typescript-eslint/no-unused-vars: [1, { vars: 'all', 'argsIgnorePattern': '^_' }] */
function foo(x, _y) {
return x + 1;
}
foo();
Please check on https://eslint.org/docs/latest/rules/no-unused-vars#options请检查https://eslint.org/docs/latest/rules/no-unused-vars#options
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.