如何告诉JSLint不要在单行if语句上要求{ [英] How to tell JSLint not to ask for { on single line if statements
问题描述
现在我有以下代码:
if (c > last) break;
jslint抱怨
jslint:crud.js:69:19:Expected '{' and instead saw 'break'.
有几种方法可以克服它:
There are several ways to overcome it:
if (c > last) { break; }
或
if (c > last) {
break;
}
但是我希望jslint在if语句在同一行时不要抱怨.
But I'd like jslint not to complain when the if statement is on the same line.
有什么方法可以配置它吗?
Is there some way to configure it?
顺便说一句:我正在使用以下配置来处理sublime文本和sublime-jslint插件:
BTW: I'm working with sublime text and the sublime-jslint plugin, with the following configuration:
{
// Path to the jslint jar.
// Leave blank to use bundled jar.
"jslint_jar": "",
// Options pass to jslint.
"jslint_options": "--indent 2 --white --maxerr 10000 --nomen --browser --plusplus --es5",
// Ignore errors, regex.
"ignore_errors":
[
"Combine this with the previous 'var' statement.",
"It is not necessary to initialize"
],
// run jslint on save.
"run_on_save": false,
// debug flag.
"debug": false
}
任何想法如何配置它?
推荐答案
不幸的是,JSLint没有提供一个配置选项来告诉它可以忍受这一点.在JSLint看来,即使条件语句或迭代语句仅包含一个语句,也要始终在条件语句或迭代语句之后加上一个block语句.
Unfortunately, JSLint does not provide a configuration option that will tell it to tolerate this. In the eyes of JSLint it is good practice to always follow a conditional or iteration statement with a block statement, even when said block would contain only a single statement.
如果您切换到更易于配置的 JSHint ,则可以使用curly
选项执行以下操作:
If you switch to JSHint, which is far more configurable, you can use the curly
option to:
/*jshint curly: false */
这会将JSHint配置为允许单个语句不带花括号,是否与前面的条件或迭代语句在同一行.
This configures JSHint to allow a single statement without curly braces, whether or not it's on the same line as the preceding conditional or iteration statement.
如果您的Sublime插件仅支持JSLint,我强烈建议您使用 SublimeLinter .它同时支持JSLint和JSHint.
If your Sublime plugin only supports JSLint, I can highly recommend SublimeLinter, which is what I use. It supports both JSLint and JSHint.
这篇关于如何告诉JSLint不要在单行if语句上要求{的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!