Skip to content

Commit

Permalink
Fix: no-debugger autofixer produced invalid syntax (#8806)
Browse files Browse the repository at this point in the history
This updates the `no-debugger` autofixer to not remove `debugger` statements that are in a position where a statement is required (e.g. the direct descendent of an `if` statement).
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Jun 27, 2017
1 parent 8698a92 commit 9417818
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rules/no-debugger.js
Expand Up @@ -5,6 +5,8 @@

"use strict";

const astUtils = require("../ast-utils");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand All @@ -28,7 +30,10 @@ module.exports = {
node,
message: "Unexpected 'debugger' statement.",
fix(fixer) {
return fixer.remove(node);
if (astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type)) {
return fixer.remove(node);
}
return null;
}
});
}
Expand Down
11 changes: 10 additions & 1 deletion tests/lib/rules/no-debugger.js
Expand Up @@ -23,6 +23,15 @@ ruleTester.run("no-debugger", rule, {
"var test = { debugger: 1 }; test.debugger;"
],
invalid: [
{ code: "debugger", errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement" }], output: "" }
{
code: "debugger",
output: "",
errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement" }]
},
{
code: "if (foo) debugger",
output: null,
errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement" }]
}
]
});

0 comments on commit 9417818

Please sign in to comment.