Suppress “Expected '===' and instead saw '=='.” error in jslint

懵懂的女人 提交于 2020-06-07 13:38:05

问题


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


回答1:


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

"eqeqeq": false

From the documentation: 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



回答2:


This is pretty hot off the press.

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

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

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 eqeq: true*/
var x = 0;
if (x == 1) {
    alert("test");
}



回答3:


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 really what you want.




回答4:


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 */


来源:https://stackoverflow.com/questions/6317892/suppress-expected-and-instead-saw-error-in-jslint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!