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

Code before:
        { code: "Array.from(x, function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.from" } }] },
        { code: "foo.every(function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] },
        { code: "foo.filter(function foo() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] },
        { code: "foo.filter(function foo() { return; })", options: checkForEachOptions, errors: [{ messageId: "expectedReturnValue", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] },
        { code: "foo.every(cb || function() {})", options: checkForEachOptions, errors: ["Array.prototype.every() expects a return value from function."] },
        { code: "foo.forEach((x) => void x)", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => void bar(x))", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },

        // options: { checkForEach: true, allowVoid: true }
        { code: "foo.forEach((x) => x)", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => !x)", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { return x; })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { return !x; })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { if (a === b) { return x; } })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },
        { code: "foo.forEach((x) => { if (a === b) { return !x } })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue" }] },

        {
            code: "foo.forEach(x => x)",
            options: checkForEachOptions,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                suggestions: [
                    { output: "foo.forEach(x => {x})" }
                ]
            }]
        },
        {
            code: "foo.forEach(x => x)",
            options: checkForEachAllowVoid,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                suggestions: [
                    { output: "foo.forEach(x => {x})" },
                    { output: "foo.forEach(x => void x)" }
                ]
            }]
        },
        {
            code: "foo.forEach((x) => { return x; })",
            options: checkForEachAllowVoid,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                suggestions: [
                    { output: "foo.forEach((x) => { return void x; })" }
                ]
            }]

Review comment (suggestion):
Can you add `messageId` to all suggestion test objects? Also, can you add `suggestions` to all test cases where the rule provides suggestions? This is for better testing and will soon be mandatory per [RFC #84](https://github.com/eslint/rfcs/blob/main/designs/2021-stricter-rule-test-validation/README.md).

Code after:
        {
            code: "foo.forEach(x => (x))",
            options: checkForEachOptions,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" },
                suggestions: [
                    { output: "foo.forEach(x => {(x)})", messageId: "wrapBraces" }
                ]
            }]
        },
        {
            code: "foo.forEach(val => y += val)",
            options: checkForEachOptions,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" },
                suggestions: [
                    { output: "foo.forEach(val => {y += val})", messageId: "wrapBraces" }
                ]
            }]
        },
        {
            code: "[\"foo\",\"bar\"].forEach(x => ++x)",
            options: checkForEachOptions,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" },
                suggestions: [
                    { output: "[\"foo\",\"bar\"].forEach(x => {++x})", messageId: "wrapBraces" }
                ]
            }]
        },
        {
            code: "foo.bar().forEach(x => x === y)",
            options: checkForEachOptions,
            parserOptions: { ecmaVersion: 6 },
            errors: [{
                messageId: "expectedNoReturnValue",
                data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" },
                suggestions: [
                    { output: "foo.bar().forEach(x => {x === y})", messageId: "wrapBraces" }
                ]
            }]
        },
        { code: "foo.forEach(function() {return function() { if (a == b) { return a; }}}())", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] },
        { code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] },
        { code: "foo.forEach(function(x) { if (a == b) {return undefined;}})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] },