有没有办法让jslint在我的javascript的下一行使用花括号?

3 javascript jquery jslint

我改变了我的编码风格

function getParams(entity) {
    "use strict";
    var accountID = store.getItem('AccountID'),

    switch (entity) {
        case "Topic":
Run Code Online (Sandbox Code Playgroud)

function getParams(entity) 
{

    "use strict";
    var accountID = store.getItem('AccountID'),

    switch (entity)
    {
        case "Topic":
Run Code Online (Sandbox Code Playgroud)

现在我得到任何jslint错误,例如:

警告6 JS Lint:预期')'和'{'之间只有一个空格.警告9 JS Lint:第9栏预期'var',而不是第5列.

我检查了选项,但找不到任何与行位置有关的取消选择.如果有的话,我可以将它添加到我的文件顶部吗?

elc*_*nrs 5

因为这个原因,建议在JavaScript中将开括号放在同一行上:

function foo()
{
  return
  {
    a: 'foo'
  }
}

foo().a // error
Run Code Online (Sandbox Code Playgroud)

这不是一个建议而是一个解决方案,但如果没有新的行,就无法在评论中解释.

  • 自动分号插入在某些关键字作为语句终止符后处理换行符.`return`是这些关键字之一.所以`return <new line here> 27`与`return; 27;`相反,而不是更直观的`return 27;`.这是ASI的一个特例.在大多数其他情况下,ASI会尽可能地继续发表声明,这会导致更加奇怪,说实话. (2认同)