Skip to content

Commit

Permalink
Fixed code that fails when AST is not deep enough.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rec0iL99 committed Oct 27, 2023
1 parent 815ce14 commit 51dd39a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/rules/no-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ module.exports = {
* @returns {boolean} `true` if a suggestion can be provided for a node.
*/
function canProvideSuggestions(node) {
const isInStatementListParents = astUtils.STATEMENT_LIST_PARENTS.has(node.parent.parent.parent.type);

return (
isInStatementListParents &&
node.parent.type === "CallExpression" &&
node.parent.callee === node &&
node.parent.parent.type === "ExpressionStatement"
node.parent.parent.type === "ExpressionStatement" &&
astUtils.STATEMENT_LIST_PARENTS.has(node.parent.parent.parent.type)
);
}

Expand All @@ -143,7 +141,7 @@ module.exports = {
messageId: "removeConsole",
data: { propertyName },
fix(fixer) {
return fixer.removeRange(node.parent.parent.range);
return fixer.remove(node.parent.parent);
}
}]
: []
Expand Down

0 comments on commit 51dd39a

Please sign in to comment.