Repository: eslint/eslint
File: lib/rules/array-callback-return.js (JavaScript)

Code before:
         *
         * If the last code path segment is reachable, there are paths which are not
         * returned or thrown.
         * @param {ASTNode} node A node to check.
         * @returns {void}
         */
        function checkLastSegment(node) {

            if (!funcInfo.shouldCheck) {
                return;
            }

            let messageId = null;

            if (funcInfo.arrayMethodName === "forEach") {
                if (options.checkForEach && node.type === "ArrowFunctionExpression" && node.expression) {
                    messageId = "expectedNoReturnValue";
                }

                if (options.checkForEach &&
                    options.allowVoid &&
                    node.type === "ArrowFunctionExpression" &&
                    node.body.type === "UnaryExpression" &&
                    node.body.operator === "void") {
                    return;
                }
            } else {
                if (node.body.type === "BlockStatement" && isAnySegmentReachable(funcInfo.currentSegments)) {
                    messageId = funcInfo.hasReturn ? "expectedAtEnd" : "expectedInside";
                }
            }

            if (messageId) {
                const name = astUtils.getFunctionNameWithKind(node);

                context.report({
                    node,
                    loc: astUtils.getFunctionHeadLoc(node, sourceCode),
                    messageId,
                    data: { name, arrayMethodName: fullMethodName(funcInfo.arrayMethodName) }
                });
            }
        }

        return {

            // Stacks this function's information.
            onCodePathStart(codePath, node) {

                let methodName = null;


Review comment (suggestion):
I think we can make this a bit easier to follow by pulling the common checks up a level.

```suggestion
                if (options.checkForEach && node.type === "ArrowFunctionExpression") {

                    if (node.expression) {
                        messageId = "expectedNoReturnValue";
                    }
    
                    if (options.allowVoid &&
                        node.body.type === "UnaryExpression" &&
                        node.body.operator === "void") {
                        return;
                    }
                }
```

Code after:
         *
         * If the last code path segment is reachable, there are paths which are not
         * returned or thrown.
         * @param {ASTNode} node A node to check.
         * @returns {void}
         */
        function checkLastSegment(node) {

            if (!funcInfo.shouldCheck) {
                return;
            }

            let messageId = null;

            if (funcInfo.arrayMethodName === "forEach") {
                if (options.checkForEach && node.type === "ArrowFunctionExpression" && node.expression) {
                    if (options.allowVoid &&
                        node.body.type === "UnaryExpression" &&
                        node.body.operator === "void") {
                        return;
                    }

                    messageId = "expectedNoReturnValue";
                }
            } else {
                if (node.body.type === "BlockStatement" && isAnySegmentReachable(funcInfo.currentSegments)) {
                    messageId = funcInfo.hasReturn ? "expectedAtEnd" : "expectedInside";
                }
            }

            if (messageId) {
                const name = astUtils.getFunctionNameWithKind(node);

                context.report({
                    node,
                    loc: astUtils.getFunctionHeadLoc(node, sourceCode),
                    messageId,
                    data: { name, arrayMethodName: fullMethodName(funcInfo.arrayMethodName) }
                });
            }
        }

        return {

            // Stacks this function's information.
            onCodePathStart(codePath, node) {

                let methodName = null;

                if (TARGET_NODE_TYPE.test(node.type)) {
                    methodName = getArrayMethodName(node);