lib/rules/newline-before-return.js
function calcCommentLines(node, lineNumTokenBefore) {
            const comments = sourceCode.getCommentsBefore(node);
            let numLinesComments = 0;

            if (!comments.length) {
                return numLinesComments;
            }

            comments.forEach(comment => {
                numLinesComments++;

                if (comment.type === "Block") {
                    numLinesComments += comment.loc.end.line - comment.loc.start.line;
                }

                // avoid counting lines with inline comments twice
                if (comment.loc.start.line === lineNumTokenBefore) {
                    numLinesComments--;
                }

                if (comment.loc.end.line === node.loc.start.line) {
                    numLinesComments--;
                }
            });

            return numLinesComments;
        }
function calcCommentLines(node, lineNumTokenBefore) {
            const comments = sourceCode.getCommentsBefore(node);
            let numLinesComments = 0;

            if (!comments.length) {
                return numLinesComments;
            }

            comments.forEach(comment => {
                numLinesComments++;

                if (comment.type === "Block") {
                    numLinesComments += comment.loc.end.line - comment.loc.start.line;
                }

                // avoid counting lines with inline comments twice
                if (comment.loc.start.line === lineNumTokenBefore) {
                    numLinesComments--;
                }

                if (comment.loc.end.line === node.loc.start.line) {
                    numLinesComments--;
                }
            });

            return numLinesComments;
        }
function calcCommentLines ( node , lineNumTokenBefore ) { const comments = sourceCode . getCommentsBefore ( node ) ; let numLinesComments = 0 ; if ( ! comments . length ) { return numLinesComments ; } comments . forEach ( comment => { numLinesComments ++ ; if ( comment . type === "Block" ) { numLinesComments += comment . loc . end . line - comment . loc . start . line ; } // avoid counting lines with inline comments twice if ( comment . loc . start . line === lineNumTokenBefore ) { numLinesComments -- ; } if ( comment . loc . end . line === node . loc . start . line ) { numLinesComments -- ; } } ) ; return numLinesComments ; }
Returns the number of lines of comments that precede the node
@param {ASTNode} node - node to check for overlapping comments
@param {number} lineNumTokenBefore - line number of previous token, to check for overlapping comments
@returns {number} Number of lines of comments that precede the node
@private
Returns the number of lines of comments that precede the node