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

前端 未结 1 677
陌清茗
陌清茗 2020-12-20 12:08

Right now I have the following code:

if (c > last) break;

And jslint complains with

jslint:crud.js:69:19:Expected \'{\'          


        
相关标签:
1条回答
  • 2020-12-20 12:30

    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.

    0 讨论(0)
提交回复
热议问题