Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

sublimetext2 - How to tell JSLint not to ask for { on single line if statements

Right now I have the following code:

if (c > last) break;

And jslint complains with

jslint:crud.js:69:19:Expected '{' and instead saw 'break'.

There are several ways to overcome it:

if (c > last) { break; }

or

if (c > last) { 
  break; 
}

But I'd like jslint not to complain when the if statement is on the same line.

Is there some way to configure it?

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
}

Any idea how to configure it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

If you switch to JSHint, which is far more configurable, you can use the curly option to:

/*jshint curly: false */

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.

If your Sublime plugin only supports JSLint, I can highly recommend SublimeLinter, which is what I use. It supports both JSLint and JSHint.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...