Disable JSHint warning: Expected an assignment or function call and instead saw an expression [duplicate]

半城伤御伤魂 提交于 2019-12-03 05:34:08

问题


I have the following line:

imageUrl && (data.imageUrl = imageUrl);

For this line, JSHint complains:

 Expected an assignment or function call and instead saw an expression.

I understand the warning, but I want to disable it. I can’t find the way how to do it. Any idea?


回答1:


If it really is just that one line

imageUrl && (data.imageUrl = imageUrl); // jshint ignore:line

I am a fan of writing code so it doesn't produce warnings, though, even if this means taking special action to do so. So I'd prefer

if (imageUrl) data.imageUrl = imageUrl;



回答2:


Include a /* jshint expr: true */ comment in your Javascript.

Reference: http://jshint.com/docs/options/#expr



来源:https://stackoverflow.com/questions/27623822/disable-jshint-warning-expected-an-assignment-or-function-call-and-instead-saw

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