lib/rules/function-paren-newline.js
function getParenTokens(node) {
            switch (node.type) {
                case "NewExpression":
                    if (!node.arguments.length && !(
                        astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
                        astUtils.isClosingParenToken(sourceCode.getLastToken(node))
                    )) {

                        // If the NewExpression does not have parens (e.g. `new Foo`), return null.
                        return null;
                    }

                    // falls through

                case "CallExpression":
                    return {
                        leftParen: sourceCode.getTokenAfter(node.callee, astUtils.isOpeningParenToken),
                        rightParen: sourceCode.getLastToken(node)
                    };

                case "FunctionDeclaration":
                case "FunctionExpression": {
                    const leftParen = sourceCode.getFirstToken(node, astUtils.isOpeningParenToken);
                    const rightParen = node.params.length
                        ? sourceCode.getTokenAfter(node.params[node.params.length - 1], astUtils.isClosingParenToken)
                        : sourceCode.getTokenAfter(leftParen);

                    return { leftParen, rightParen };
                }

                case "ArrowFunctionExpression": {
                    const firstToken = sourceCode.getFirstToken(node);

                    if (!astUtils.isOpeningParenToken(firstToken)) {

                        // If the ArrowFunctionExpression has a single param without parens, return null.
                        return null;
                    }

                    return {
                        leftParen: firstToken,
                        rightParen: sourceCode.getTokenBefore(node.body, astUtils.isClosingParenToken)
                    };
                }

                default:
                    throw new TypeError(`unexpected node with type ${node.type}`);
            }
        }
function getParenTokens(node) {
            switch (node.type) {
                case "NewExpression":
                    if (!node.arguments.length && !(
                        astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
                        astUtils.isClosingParenToken(sourceCode.getLastToken(node))
                    )) {

                        // If the NewExpression does not have parens (e.g. `new Foo`), return null.
                        return null;
                    }

                    // falls through

                case "CallExpression":
                    return {
                        leftParen: sourceCode.getTokenAfter(node.callee, astUtils.isOpeningParenToken),
                        rightParen: sourceCode.getLastToken(node)
                    };

                case "FunctionDeclaration":
                case "FunctionExpression": {
                    const leftParen = sourceCode.getFirstToken(node, astUtils.isOpeningParenToken);
                    const rightParen = node.params.length
                        ? sourceCode.getTokenAfter(node.params[node.params.length - 1], astUtils.isClosingParenToken)
                        : sourceCode.getTokenAfter(leftParen);

                    return { leftParen, rightParen };
                }

                case "ArrowFunctionExpression": {
                    const firstToken = sourceCode.getFirstToken(node);

                    if (!astUtils.isOpeningParenToken(firstToken)) {

                        // If the ArrowFunctionExpression has a single param without parens, return null.
                        return null;
                    }

                    return {
                        leftParen: firstToken,
                        rightParen: sourceCode.getTokenBefore(node.body, astUtils.isClosingParenToken)
                    };
                }

                default:
                    throw new TypeError(`unexpected node with type ${node.type}`);
            }
        }
function getParenTokens ( node ) { switch ( node . type ) { case "NewExpression" : if ( ! node . arguments . length && ! ( astUtils . isOpeningParenToken ( sourceCode . getLastToken ( node , { skip : 1 } ) ) && astUtils . isClosingParenToken ( sourceCode . getLastToken ( node ) ) ) ) { // If the NewExpression does not have parens (e.g. `new Foo`), return null. return null ; } // falls through case "CallExpression" : return { leftParen : sourceCode . getTokenAfter ( node . callee , astUtils . isOpeningParenToken ) , rightParen : sourceCode . getLastToken ( node ) } ; case "FunctionDeclaration" : case "FunctionExpression" : { const leftParen = sourceCode . getFirstToken ( node , astUtils . isOpeningParenToken ) ; const rightParen = node . params . length ? sourceCode . getTokenAfter ( node . params [ node . params . length - 1 ] , astUtils . isClosingParenToken ) : sourceCode . getTokenAfter ( leftParen ) ; return { leftParen , rightParen } ; } case "ArrowFunctionExpression" : { const firstToken = sourceCode . getFirstToken ( node ) ; if ( ! astUtils . isOpeningParenToken ( firstToken ) ) { // If the ArrowFunctionExpression has a single param without parens, return null. return null ; } return { leftParen : firstToken , rightParen : sourceCode . getTokenBefore ( node . body , astUtils . isClosingParenToken ) } ; } default : throw new TypeError ( ` ${ node . type } ` ) ; } }
Gets the left paren and right paren tokens of a node.
@param {ASTNode} node The node with parens
@returns {Object} An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token.
Can also return `null` if an expression has no parens (e.g. a NewExpression with no arguments, or an ArrowFunctionExpression
with a single parameter)
Gets the left paren and right paren tokens of a node .