Skip to content

Commit

Permalink
Update: Improve array-callback-return report (explains why) patch
Browse files Browse the repository at this point in the history
* Made tests match proposed new message.
  • Loading branch information
mrflip committed Jun 28, 2020
1 parent 65374e1 commit 0cdf1a8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions tests/lib/rules/array-callback-return.js
Expand Up @@ -145,27 +145,27 @@ ruleTester.run("array-callback-return", rule, {
{ code: "foo[\"every\"](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo[`every`](function() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "every" } }] },
{ code: "foo[`every`](function foo() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(() => {})", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method .every() expected a return value from arrow function.", column: 14 }] },
{ code: "foo.every(function() { if (a) return true; })", errors: [{ message: "Method .every() expected a value to be returned at the end of function.", column: 11 }] },
{ code: "foo.every(function cb() { if (a) return true; })", errors: [{ message: "Method .every() expected a value to be returned at the end of function 'cb'.", column: 11 }] },
{ code: "foo.every(() => {})", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expected a return value from arrow function.", column: 14 }] },
{ code: "foo.every(function() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expected a value to be returned at the end of function.", column: 11 }] },
{ code: "foo.every(function cb() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expected a value to be returned at the end of function 'cb'.", column: 11 }] },
{ code: "foo.every(function() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(function() { try { bar(); } catch (err) { return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { try { bar(); } catch (err) { return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(function() { return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(function() { if (a) return; })", errors: ["Method .every() expected a value to be returned at the end of function.", { messageId: "expectedReturnValue", data: { name: "Function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { if (a) return; })", errors: ["Method .every() expected a value to be returned at the end of function 'foo'.", { messageId: "expectedReturnValue", data: { name: "Function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(function() { if (a) return; })", errors: ["Array.prototype.every() expected a value to be returned at the end of function.", { messageId: "expectedReturnValue", data: { name: "Function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { if (a) return; })", errors: ["Array.prototype.every() expected a value to be returned at the end of function 'foo'.", { messageId: "expectedReturnValue", data: { name: "Function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(function() { if (a) return; else return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function" } }, { messageId: "expectedReturnValue", data: { name: "Function", arrayMethodName: "every" } }] },
{ code: "foo.every(function foo() { if (a) return; else return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function 'foo'" } }, { messageId: "expectedReturnValue", data: { name: "Function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(cb || function() {})", errors: ["Method .every() expected a return value from function."] },
{ code: "foo.every(cb || function foo() {})", errors: ["Method .every() expected a return value from function 'foo'."] },
{ code: "foo.every(a ? function() {} : function() {})", errors: ["Method .every() expected a return value from function.", "Method .every() expected a return value from function."] },
{ code: "foo.every(a ? function foo() {} : function bar() {})", errors: ["Method .every() expected a return value from function 'foo'.", "Method .every() expected a return value from function 'bar'."] },
{ code: "foo.every(function(){ return function() {}; }())", errors: [{ message: "Method .every() expected a return value from function.", column: 30 }] },
{ code: "foo.every(function(){ return function foo() {}; }())", errors: [{ message: "Method .every() expected a return value from function 'foo'.", column: 30 }] },
{ code: "foo.every(() => {})", options: [{ allowImplicit: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method .every() expected a return value from arrow function." }] },
{ code: "foo.every(() => {})", options: [{ allowImplicit: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method .every() expected a return value from arrow function." }] },
{ code: "foo.every(cb || function() {})", errors: ["Array.prototype.every() expected a return value from function."] },
{ code: "foo.every(cb || function foo() {})", errors: ["Array.prototype.every() expected a return value from function 'foo'."] },
{ code: "foo.every(a ? function() {} : function() {})", errors: ["Array.prototype.every() expected a return value from function.", "Array.prototype.every() expected a return value from function."] },
{ code: "foo.every(a ? function foo() {} : function bar() {})", errors: ["Array.prototype.every() expected a return value from function 'foo'.", "Array.prototype.every() expected a return value from function 'bar'."] },
{ code: "foo.every(function(){ return function() {}; }())", errors: [{ message: "Array.prototype.every() expected a return value from function.", column: 30 }] },
{ code: "foo.every(function(){ return function foo() {}; }())", errors: [{ message: "Array.prototype.every() expected a return value from function 'foo'.", column: 30 }] },
{ code: "foo.every(() => {})", options: [{ allowImplicit: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expected a return value from arrow function." }] },
{ code: "foo.every(() => {})", options: [{ allowImplicit: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expected a return value from arrow function." }] },

// options: { allowImplicit: true }
{ code: "Array.from(x, function() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "from" } }] },
Expand All @@ -176,7 +176,7 @@ ruleTester.run("array-callback-return", rule, {
{ code: "foo.reduce(function() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "reduce" } }] },
{ code: "foo.reduceRight(function() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "reduceRight" } }] },
{ code: "foo.bar.baz.every(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "every" } }] },
{ code: "foo.every(cb || function() {})", options: allowImplicitOptions, errors: ["Method .every() expected a return value from function."] },
{ code: "foo.every(cb || function() {})", options: allowImplicitOptions, errors: ["Array.prototype.every() expected a return value from function."] },
{ code: "[\"foo\",\"bar\"].sort(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "sort" } }] },
{ code: "foo.forEach(x => x)", options: allowImplicitCheckForEach, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "Arrow function" } }] },
{ code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "Function" } }] },
Expand All @@ -198,7 +198,7 @@ ruleTester.run("array-callback-return", rule, {
{ code: "foo.every(function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "every" } }] },
{ code: "foo.filter(function foo() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "filter" } }] },
{ code: "foo.filter(function foo() { return; })", options: checkForEachOptions, errors: [{ messageId: "expectedReturnValue", data: { name: "Function 'foo'", arrayMethodName: "filter" } }] },
{ code: "foo.every(cb || function() {})", options: checkForEachOptions, errors: ["Method .every() expected a return value from function."] },
{ code: "foo.every(cb || function() {})", options: checkForEachOptions, errors: ["Array.prototype.every() expected a return value from function."] },

// full location tests
{
Expand Down

0 comments on commit 0cdf1a8

Please sign in to comment.