javascript – Jslint“换行错误”

前端之家收集整理的这篇文章主要介绍了javascript – Jslint“换行错误”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
此片段的JSLint验证
1: function foo() {}
2: 
3: foo(1
4: );
5: 
6: foo(
7: );

给出了这个错误

Error:

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

foo(1

这是一个JSLint错误吗?

解决方法

这不是一个错误. JSLint不仅仅是语法检查:它强制执行某些编码约定.如果您在启用“Tolerate sloppy line breaking”选项的情况下重新验证​​,则不会出现错误.

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.

猜你在找的JavaScript相关文章