Javascript 禁止“预期的 '===',而是看到了 '=='。” jslint 中的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6317892/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:15:09  来源:igfitidea点击:

Suppress "Expected '===' and instead saw '=='." error in jslint

javascriptdebuggingjslint

提问by usertest

How can I stop the error message Expected '===' and instead saw '=='.from appearing in jslint. Doesn't seem to be an option.

如何阻止错误消息Expected '===' and instead saw '=='.出现在 jslint 中。似乎不是一个选择。

回答by bubbassauro

For those using JSHint, you can turn off this warning by setting the option eqeqeqto false in your JSHint options (usually .jshintrc)

对于那些使用 JSHint 的人,您可以通过在JSHint选项(通常是.jshintrc)中将选项eqeqeq设置为 false 来关闭此警告

"eqeqeq": false

From the documentation: http://jshint.com/docs/options/#eqeqeq

从文档:http: //jshint.com/docs/options/#eqeqeq

Edit:

编辑:

If you want to be a good citizen and fix your code to use the recommended comparison instead of turning the warning off, make sure both sides of the comparison are using the same type.

如果您想成为一个好公民并修复您的代码以使用推荐的比较而不是关闭警告,请确保比较的双方使用相同的类型。

For example:

例如:

"123" == 123          // true, I'm lazy and JSHint hates me
"123" === 123         // false, no love
Number("123") === 123 // true, no warning

回答by James Wiseman

This is pretty hot off the press.

这在媒体上非常热门。

Douglas Crockford has just added an 'eqeq' option to the JSLint tool.

Douglas Crockford 刚刚向 JSLint 工具添加了一个“eqeq”选项。

See one of the June 12, 2011 edits on GitHub:

在 GitHub 上查看 2011 年 6 月 12 日的编辑之一:

https://github.com/douglascrockford/JSLint/commits/2e8d430b5b9543caefb3743513181f1295f52ddf/jslint.js

https://github.com/douglascrockford/JSLint/commits/2e8d430b5b9543caefb3743513181f1295f52ddf/jslint.js

Ad the time of writing it hadn't been updated on the JSLint front page, but i've tested it with the following and get no ==related warnings:

广告在 JSLint 首页上尚未更新,但我已经使用以下内容对其进行了测试,并且没有收到==相关警告:

/*jslint eqeq: true*/
var x = 0;
if (x == 1) {
    alert("test");
}

回答by Matthew Crumley

You are correct that there is no option for that. The only way is to either use ===or modify the source code. I almost always use ===anyway. It's better in general unless you know that ==is reallywhat you want.

你是对的,没有选择。唯一的方法是使用===或修改源代码===反正我几乎总是用。这是一般的好,除非你知道==真的,你想要什么。

回答by Pradeep Potnuru

Although its late its worth, it would help some one who is in need

虽然晚了,但它会帮助一些有需要的人

To disable use -

禁用使用 -

/* eslint eqeqeq: 0 */

To make it as warning use -

将其作为警告使用 -

/* eslint eqeqeq: 1 */