简体   繁体   English

期望赋值或函数调用,而是看到了一个表达式

[英]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};

I don't think JSLint has an option to turn that off.我认为 JSLint 没有关闭它的选项。

JSHint (a fork with more options) has an option for it, though: The expr option, documented as "if ExpressionStatement should be allowed as Programs".不过,JSHint (一个具有更多选项的分支)有一个选项: expr选项,记录为“如果 ExpressionStatement 应该被允许作为程序”。

You can add the following line to ignore that warning:您可以添加以下行来忽略该警告:

/*jshint -W030 */ /*jshint -W030 */

You can read more about ithere .您可以在此处阅读更多相关信息。

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.

相关问题 期望一个赋值或函数调用,而是看到一个表达式? - Expected an assignment or function call and instead saw an expression? 期望一个赋值或函数调用,而是看到一个表达式 - Expected an assignment or function call and instead saw an expression return function returning预期的赋值或函数调用,而是看到一个表达式 - return function returning Expected an assignment or function call and instead saw an expression 期望赋值或函数调用,但在函数中看到表达式错误 - Expected an assignment or function call and instead saw an expression error in function Javascript:JSHint:需要一个赋值或函数调用,而是看到一个表达式 - Javascript: JSHint: Expected an assignment or function call and instead saw an expression 错误-预期分配或函数调用,而是看到一个表达式 - Error - Expected an assignment or function call and instead saw an expression ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” 警告带有主干的JSHint:预期分配或函数调用,而是看到一个表达式 - Warning JSHint with backbone : Expected an assignment or function call and instead saw an expression 错误:预期分配或函数调用,而是看到一个表达式 - Error: expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是在定义接口时看到一个表达式 - Expected an assignment or function call and instead saw an expression when defining interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM