no-debugger
禁止使用 debugger
在 配置文件 中使用来自 @eslint/js
的 recommended
配置可以启用此规则
debugger
语句用于告诉正在执行的 JavaScript 环境停止执行并在代码的当前点启动调试器。随着现代调试和开发工具的出现,这已不再是一种良好的做法。生产代码绝对不能包含 debugger
,因为它会导致浏览器停止执行代码并打开适当的调试器。
¥The debugger
statement is used to tell the executing JavaScript environment to stop execution and start up a debugger at the current point in the code. This has fallen out of favor as a good practice with the advent of modern debugging and development tools. Production code should definitely not contain debugger
, as it will cause the browser to stop executing code and open an appropriate debugger.
规则详情
¥Rule Details
此规则不允许 debugger
语句。
¥This rule disallows debugger
statements.
此规则的错误代码示例:
¥Example of incorrect code for this rule:
/*eslint no-debugger: "error"*/
function isTruthy(x) {
debugger;
return Boolean(x);
}
此规则的正确代码示例:
¥Example of correct code for this rule:
/*eslint no-debugger: "error"*/
function isTruthy(x) {
return Boolean(x); // set a breakpoint at this line
}
何时不使用
¥When Not To Use It
如果你的代码仍处于开发阶段并且不想担心剥离 debugger
语句,请关闭此规则。在部署之前测试代码时,你通常希望将其重新打开。
¥If your code is still very much in development and don’t want to worry about stripping debugger
statements, then turn this rule off. You’ll generally want to turn it back on when testing code prior to deployment.
相关规则
版本
此规则是在 ESLint v0.0.2 中引入。