[英]Expected an assignment or function call and instead saw an expression
I'm totally cool with this JSLint error.我对这个JSLint错误非常满意。 How can I tolerate it?
我怎么能忍受呢? Is there a flag or checkbox for it?
是否有标志或复选框?
You get it when you do stuff like:当你做这样的事情时你会得到它:
v && arr.push(v);
as opposed to:与:
if (v) {
arr.push(v);
}
Both do the same exact thing.两者都做同样的事情。 If you put:
如果你把:
window.test = function(v) {
'use strict';
var arr = [];
if (v) {
arr.push(v);
}
return arr;
};
into the minifier it minifies down to this anyway:进入压缩器它无论如何都会缩小到这个:
window.test=function(a){var b=[];a&&b.push(a);return b};
People who are looking how to suppress it when using ESLint .正在寻找如何在使用ESLint时抑制它的人。 You can ingnore it by writing the following comment just above the line no-unused-expressions
您可以通过在no-unused-expressions行上方写下以下注释来忽略它
// eslint-disable-next-line no-unused-expressions
You can also suppress the warning for the entire file by placing the following comment at the very top of the file您还可以通过在文件的最顶部放置以下注释来抑制整个文件的警告
/* eslint-disable no-unused-expressions */
There's no option for this in JSLint.在 JSLint 中没有这个选项。 You can circumvent it using:
您可以使用以下方法规避它:
var dummy = v && arr.push(v);
NB: dummy
evaluates to true
after that.注意:
dummy
评估为true
。
Another workaround could be:另一种解决方法可能是:
function expression(statement) {
'use strict';
return statement;
}
expression(v && arr.push);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.