JSLint:控制注释(选择性忽略)
Does JSLint have anything like JavaScript Lint's control comments (e.g. /*jsl:fallthru*/
) to make it ignore certain passages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
放在
之前和
要忽略的代码 之后。 例如:
或者导出 JsLint 设置,定义 IgnoreErrorStart/ IgnoreErrorEnd 符号并导入。
Edit
Some folks may confuse this answer with JSHint. In that case, use these:
摘自https://stackoverflow.com/a/26012357/313501
Put
before and
after the code to be ignored. Ex:
Or export JsLint settings, define your IgnoreErrorStart/ IgnoreErrorEnd symbols and import.
Edit
Some folks may confuse this answer with JSHint. In that case, use these:
Taken from https://stackoverflow.com/a/26012357/313501
是的。 从文档中[注意,这是来自旧版本的文档,但它仍然适用]:
文档没有具体提及它,但您可以使用多个 jslint 注释在整个代码中启用和禁用不同的检查(感谢 Dominic Mitchell)。
文档中有完整的选项列表。
Yes. From the documentation [note that this is from an older version of the docs, but it still applies]:
The documentation doesn't specifically mention it, but you can enable and disable different checks throughout the code with multiple jslint comments (thanks Dominic Mitchell).
There is a complete list of options in the documentation.
这是一个代码示例来补充 Matthew Crumley 的出色答案:
Here is a code example to supplement Matthew Crumley's excellent answer:
据我所知,这里没有任何内容可以回答这个问题。 以下代码仍然给我带来验证错误,并且我无法让 JSLint 接受我现在没有时间在给定实际优先级的情况下更正工作正则表达式。
我收到的错误涉及未转义的“{”,可能会导致我的新专业团队拒绝将 JSLint 作为可行的工具。 似乎没有办法阻止我们为更有效地发展所做的努力,这似乎是有问题的。
Nothing here has answered this question as far as I am able to tell. The following code still gives me validation errors and I can't get JSLint to accept that I don't have time to correct a working regular expression right now given ACTUAL PRIORITIES.
The error I'm receiving regards an unescaped '{' and may result in my new, professional team rejecting JSLint as a feasible tool. There appears to be no way to shut it up regarding our efforts to develop more efficiently, which seems problematic.
看来并非如此。 一些谷歌搜索发现了其他人的几篇帖子,以及 JSLint 人员的回复,大意是“修复你的代码,而不是故意标记它有缺陷”。 看起来并不完全友好。 当然,也许在这种情况下您应该只修复代码,但我将其留给您来回答。
It doesn't seem so. Some Googling finds several posts by others, and responses from JSLint people along the lines of "Fix your code instead of labeling it intentionally defective." Doesn't seem entirely friendly. Of course, maybe in this case you should just fix the code, but I leave that for you to answer.
您还可以:......
ignoreThis(); // jslint 忽略:行
有没有一种方法可以抑制给定行的 JSHint 警告?
You can also: ......
ignoreThis(); // jslint ignore:line
Is there a way to suppress JSHint warning for one given line?
我想说,不。JSLint 似乎没有一个简单的方法来表示“忽略这段代码”,这让我很恼火。 单独禁用不同的选项,然后像马特建议的那样重新打开它们应该可行,但它不会像 JSHint 的
/* jshintignore:start */
、/* jshint 那样优雅忽略:结束*/
。我之所以研究这个问题是因为我使用的是 Brackets,它附带 JSLint 作为默认的 linter。 我暂时将一些缩小的第 3 方代码复制到我的 .js 中,只要它在那里,JSLint 就会抱怨。 糟糕的是我经常想尽早粘贴一个缩小的块,这也是当我希望 linter 查看我的代码来帮助我排除模糊错误时。 稍后我将使用 Grunt 缩小并连接所有内容,但无法尽早禁用它的块真的非常非常烦人。
I'm going to say, No. JSLint does not seem to have a simple way to say, 'ignore this block of code', very much to my annoyance. Disabling the different options individually and then turning them back on like Matt seems to suggest should work, but it's not going to be elegant like JSHint's
/* jshint ignore:start */
,/* jshint ignore:end */
.The reason I was looking into this is because I'm using Brackets, which comes with JSLint as it's default linter. I have some minified 3rd party code that I copied into my .js, temporarily, and as long as it's in there JSLint is going to complain. What stinks is I often want to paste a minified chunk early on, which is also when I want the linter looking at my code to help me rule out obscure errors. Later I'll just minify and concat everything with Grunt, but not being able to disable it for a block early on is really, really, annoying.
这似乎对我有用。 (使用 zedapp 中嵌入的 jslint - zedapp.org)
This seems to work for me. (using the jslint embedded in zedapp - zedapp.org)
将
/*jsl:ignore*/
和/*jsl:end*/
放在代码周围。Put
/*jsl:ignore*/
and/*jsl:end*/
around the code.