2009-02-18 6 views
7

de validation JSLint de cet extraitJSLint "Erreur rupture de ligne"

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

donne cette erreur:

 
Error: 

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

foo(1 

Est-ce un bug JSLint?

Répondre

13

Ce n'est pas un bug. JSLint fait plus que de la vérification syntaxique: il impose certaines conventions de codage. Si vous revalidez avec l'option "Tolerate sloppy line breaking" activée, vous n'obtiendrez pas d'erreur.

De l'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.

Questions connexes