'debugger' command and JSLint

我们两清 提交于 2019-12-19 01:45:51

问题


Google Chrome supports debugger command as a tool to setup a breakpoint in code. How can I hide warnings for the following code in JSLint:

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

function test() {

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

回答1:


JSLint has an explicit option to tolerate debugger statements, called debug:

debug: true if debugger statements should be allowed.

You can specify this option via your jslint directive:

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



回答2:


This error is raised to highlight a lack of convention and possible oversight by the developer.

You can disable it via:

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



回答3:


Appears debug is gone, and this is now tolerated with the devel option, with the side effect that // TODO: etc are also tolerated with the single devel option.

devel: true if browser globals that are useful in development should be predefined, and if debugger statements and TODO comments should be allowed. It adds the same globals as this directive:

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

Be sure to turn this option off before going into production.

This lints:

/*jslint white, devel */

function test() {
        "use strict";
        debugger;     // JSLint reports the "Unexpected 'debugger'" error
}



回答4:


in react I used to do it during development like this:

debugger // eslint-disable-line



回答5:


Disable no-debugger to make it work! (only applicable in Typescript tslint)

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


来源:https://stackoverflow.com/questions/20884258/debugger-command-and-jslint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!