【问题标题】:'debugger' command and JSLint“调试器”命令和 JSLint
【发布时间】:2014-01-19 23:28:44
【问题描述】:

Google Chrome 支持debugger command 作为在代码中设置断点的工具。如何在JSLint 中隐藏以下代码的警告:

/*globals $, console, */
/*jslint browser:true, white: true */

function test() {

        "use strict";
        debugger;     // JSLint reports the "Unexpected 'debugger'" error
}

【问题讨论】:

    标签: javascript google-chrome jslint


    【解决方案1】:

    JSLint 有一个explicit option 可以容忍debugger 语句,称为debug

    debug: true if debugger 语句应该被允许。

    您可以通过 jslint 指令指定此选项:

    /*jslint browser:true, white: true, debug: true */
    

    【讨论】:

    • +1 首选答案,否则您必须在多个位置实施ignore jslint
    【解决方案2】:

    提出此错误是为了强调缺乏约定和开发人员可能的疏忽。

    您可以通过以下方式禁用它:

    function test() {
        /* ignore jslint start */
        debugger;
        /* ignore jslint end */
    }
    

    【讨论】:

      【解决方案3】:

      出现debug 消失了,this is now tolerated with the devel option 出现了 // TODO: 等副作用,也可以使用单个 devel 选项。

      devel: true 如果在开发中有用的浏览器全局变量应该是 预定义的,如果 debugger 语句和 TODO cmets 应该是 允许。它添加了与该指令相同的全局变量:

      /*global
          alert, confirm, console, prompt
      */
      

      确保在投入生产之前关闭此选项。

      这个 lints:

      /*jslint white, devel */
      
      function test() {
              "use strict";
              debugger;     // JSLint reports the "Unexpected 'debugger'" error
      }
      

      【讨论】:

        【解决方案4】:

        在反应中,我曾经在开发过程中这样做:

        debugger // eslint-disable-line
        

        【讨论】:

          【解决方案5】:

          禁用no-debugger 使其工作! (仅适用于 Typescript tslint

          "rules": {
              "no-debugger": false
           }
          

          【讨论】:

            猜你喜欢
            • 2013-02-09
            • 1970-01-01
            • 1970-01-01
            • 2011-06-26
            • 2016-09-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多