• [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');
    }
  • 相关阅读:
    c#代码:使用假设的方法遍历解决“谁养鱼”问题(据说是爱因斯坦所出的一道推理题) 无为而为
    远洋地暖的使用步骤
    合伙人四大原则
    model y搭载60度磷酸铁锂电池的续航表现
    model3家用充电桩按220V还是380V区别?
    食用油的挑选标准
    职责链模式(Chain of Responsibility)
    通用数据链接(UDL)的用法
    Oracle REGEXP_INSTR 用法
    访问者模式(Visitor)
  • 原文地址:https://www.cnblogs.com/shuman/p/3977118.html
Copyright © 2020-2023  润新知