Skip to content

Commit

Permalink
Updated function name to canProvideSuggestions. Added better descript…
Browse files Browse the repository at this point in the history
…ion for the function.
  • Loading branch information
Rec0iL99 committed Oct 27, 2023
1 parent aa1d8a4 commit 815ce14
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/rules/no-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,22 @@ module.exports = {
}

/**
* Checks if it is safe to provide suggestions for the specific node.
* Checks if the MemberExpression node's parent.parent.parent is a
* Program, BlockStatement, StaticBlock, or SwitchCase node. This check
* is necessary to avoid providing a suggestion that might cause a syntax error.
*
* eg. if (a) console.log(b), removing console.log() here will lead to a
* syntax error.
* if (a) { console.log(b) }, removing console.log() here is acceptable.
*
* Additionally, it checks if the callee of the CallExpression node is
* the node itself.
*
* eg. foo(console.log), cannot provide a suggestion here.
* @param {ASTNode} node The MemberExpression node to check.
* @returns {boolean} `true` if the node is safe to be fixed via a suggestion
* @returns {boolean} `true` if a suggestion can be provided for a node.
*/
function isSafeToProvideSuggestions(node) {
function canProvideSuggestions(node) {
const isInStatementListParents = astUtils.STATEMENT_LIST_PARENTS.has(node.parent.parent.parent.type);

return (
Expand All @@ -127,7 +138,7 @@ module.exports = {
node,
loc: node.loc,
messageId: "unexpected",
suggest: isSafeToProvideSuggestions(node)
suggest: canProvideSuggestions(node)
? [{
messageId: "removeConsole",
data: { propertyName },
Expand Down

0 comments on commit 815ce14

Please sign in to comment.