简体   繁体   中英

Jslint “Line breaking error”

JSLint validation of this snippet

1: function foo() {}
2: 
3: foo(1
4: );
5: 
6: foo(
7: );

gives this error:

Error:

Problem at line 3 character 5: Line breaking error ')'.

foo(1

Is this a JSLint bug?

It's not a bug. JSLint does more than syntax checking: It enforces certain coding conventions. If you revalidate with the "Tolerate sloppy line breaking" option turned on, you won't get an error.

From the JSLint Documentation :

Line Breaking

As a further defense against the semicolon insertion mechanism, JSLint expects long statements to be broken only after one of these punctuation characters or operators:

, . ; : { } ( [ = < > ? ! + - * / % ~ ^ | & == != <= >= += -= *= /= %= ^= |= &= << >> || && === !== <<= >>= >>> >>>=

JSLint does not expect to see a long statement broken after an identifier, a string, a number, closer, or a suffix operator:

) ] ++ --

JSLint allows you to turn on the Tolerate sloppy line breaking (laxbreak) option.

Semicolon insertion can mask copy/paste errors. If you always break lines after operators, then JSLint can do better at finding them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM