lib/rules/prefer-object-spread.js
function needsParens(node, sourceCode) {
    const parent = node.parent;

    switch (parent.type) {
        case "VariableDeclarator":
        case "ArrayExpression":
        case "ReturnStatement":
        case "CallExpression":
        case "Property":
            return false;
        case "AssignmentExpression":
            return parent.left === node && !isParenthesised(sourceCode, node);
        default:
            return !isParenthesised(sourceCode, node);
    }
}
function needsParens(node, sourceCode) {
    const parent = node.parent;

    switch (parent.type) {
        case "VariableDeclarator":
        case "ArrayExpression":
        case "ReturnStatement":
        case "CallExpression":
        case "Property":
            return false;
        case "AssignmentExpression":
            return parent.left === node && !isParenthesised(sourceCode, node);
        default:
            return !isParenthesised(sourceCode, node);
    }
}
function needsParens ( node , sourceCode ) { const parent = node . parent ; switch ( parent . type ) { case "VariableDeclarator" : case "ArrayExpression" : case "ReturnStatement" : case "CallExpression" : case "Property" : return false ; case "AssignmentExpression" : return parent . left === node && ! isParenthesised ( sourceCode , node ) ; default : return ! isParenthesised ( sourceCode , node ) ; } }
Helper that checks if the node needs parentheses to be valid JS.
The default is to wrap the node in parentheses to avoid parsing errors.
@param {ASTNode} node - The node that the rule warns on
@param {Object} sourceCode - in context sourcecode object
@returns {boolean} - Returns true if the node needs parentheses
Helper that checks if the node needs parentheses to be valid JS . The default is to wrap the node in parentheses to avoid parsing errors .