UNPKG

1.22 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag use of a debugger statement
3 * @author Nicholas C. Zakas
4 */
5
6"use strict";
7
8const astUtils = require("../ast-utils");
9
10//------------------------------------------------------------------------------
11// Rule Definition
12//------------------------------------------------------------------------------
13
14module.exports = {
15 meta: {
16 docs: {
17 description: "disallow the use of `debugger`",
18 category: "Possible Errors",
19 recommended: true,
20 url: "https://eslint.org/docs/rules/no-debugger"
21 },
22 fixable: "code",
23 schema: [],
24 messages: {
25 unexpected: "Unexpected 'debugger' statement."
26 }
27 },
28
29 create(context) {
30
31 return {
32 DebuggerStatement(node) {
33 context.report({
34 node,
35 messageId: "unexpected",
36 fix(fixer) {
37 if (astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type)) {
38 return fixer.remove(node);
39 }
40 return null;
41 }
42 });
43 }
44 };
45
46 }
47};