'debugger'命令和 JSLint



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

/*globals $, console, */
/*jslint browser:true, white: true */
function test() {
        "use strict";
        debugger;     // JSLint reports the "Unexpected 'debugger'" error
}

JSLint 有一个显式选项来容忍debugger语句,称为debug

debugtrue是否应允许debugger语句。

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

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

引发此错误是为了强调开发人员缺乏约定和可能的监督。

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

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

似乎debug消失了,现在devel选项可以容忍这种情况,副作用是单devel选项也可以容忍// TODO:等。

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

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

请务必在投入生产之前关闭此选项。

这根棉绒:

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

在 react 中,我曾经在开发过程中这样做,如下所示:

debugger // eslint-disable-line

禁用no-debugger使其正常工作!(仅适用于打字稿

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

最新更新