[label][javascript-Unit Test][JSLint]A Guide To JSLint Messages

原文链接:  

  http://www.jameswiseman.com/blog/2011/03/26/coding-convention-an-style-guide/

  http://www.jameswiseman.com/blog/2011/01/17/jslint-a-guide-to-jslint-messages/

The Messages

  Expected '{a}' at column {b}, not column {c}.

  这是一个简单的代码错误缩进例子,可以通过下面代码片段来看这个最简单的事例。

var a = 0;
  var b = 0; //Problem at line 2 character 3: Expected 'var' ar column 1, not column 3

  

  Expected '{a}' to have an indentation of {b} instead of {c}.

  这是另一个缩进的问题,默认的缩进step是4,意味着缩进列应该从位置开始1, 5, 9, 13, 17, etc.

  下面的例子使用了5个空格的缩进,作为一个新行的开始位置就将会是字符6(character 6),正如提示信息所表示的意思。

 

function MyFunc() {
        alert('hello'); //Problme at line 2 character 6: Expected 'alert' at column 5, not column 6.
//3456789
}

  

  Expected exactly one space between '{a}' and '{b}'.

  这条提示是JSLint对于花括号正确位置的要求,如下的代码片段在JSLint中执行就会产生这样的提示。

if (x === 0)
{  //brace on the next line
     alert("hello");
}

  即使你已经将花括号放置在了正确的位置(与if同一行),JSLint还是需要你使用正确的空格。所以,下面的代码片段一样也会产生这个提示信息:

if (x === 0){ // no spaces
     alert('hello');
}

if(x === 0)  { // two spaces
     alert('hello');
}

  Missing spaces and tabs.

  这个提示信息是因为在一行的缩进是空格和tabs的混合。大部分的IDES(集成开发环境)都会有一个将tabs自动转换为空格的选项,建议你开启这个选项。

  Unexpected space between '{a}' and '{b}'

  该提示信息是因为在不需要空格的地方使用了空格,下面的这段代码段就将会产生这个提示信息:

  

if ( x === 0){ // Unexpected space between '(' and 'x'
     alert('hello');
}
原文地址:https://www.cnblogs.com/shuman/p/3977118.html