-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: Add allowImplicit option to array-callback-return (fixes #8539) #9344
Changes from 1 commit
e88c1b5
9525db7
a83ba9d
4407058
d5c37b0
b01deb0
7bb4bf7
ed79336
a6a606f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,22 @@ const rule = require("../../../lib/rules/array-callback-return"), | |
|
||
const ruleTester = new RuleTester(); | ||
|
||
const options = [{ allowImplicit: true }]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be made clearer by naming it |
||
|
||
ruleTester.run("array-callback-return", rule, { | ||
valid: [ | ||
|
||
// options: { allowImplicit: false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to see at least one test that explicitly tests with |
||
"Array.from(x, function() { return true; })", | ||
"Int32Array.from(x, function() { return true; })", | ||
|
||
// options: { allowImplicit: true } | ||
{ code: "Array.from(x, function() { return; })", options }, | ||
{ code: "Int32Array.from(x, function() { return; })", options }, | ||
|
||
"Arrow.from(x, function() {})", | ||
|
||
// options: { allowImplicit: false } | ||
"foo.every(function() { return true; })", | ||
"foo.filter(function() { return true; })", | ||
"foo.find(function() { return true; })", | ||
|
@@ -28,17 +39,39 @@ ruleTester.run("array-callback-return", rule, { | |
"foo.reduceRight(function() { return true; })", | ||
"foo.some(function() { return true; })", | ||
"foo.sort(function() { return 0; })", | ||
|
||
// options: { allowImplicit: true } | ||
{ code: "foo.every(function() { return; })", options }, | ||
{ code: "foo.filter(function() { return; })", options }, | ||
{ code: "foo.find(function() { return; })", options }, | ||
{ code: "foo.findIndex(function() { return; })", options }, | ||
{ code: "foo.map(function() { return; })", options }, | ||
{ code: "foo.reduce(function() { return; })", options }, | ||
{ code: "foo.reduceRight(function() { return; })", options }, | ||
{ code: "foo.some(function() { return; })", options }, | ||
{ code: "foo.sort(function() { return; })", options }, | ||
|
||
"foo.abc(function() {})", | ||
"every(function() {})", | ||
"foo[every](function() {})", | ||
"var every = function() {}", | ||
{ code: "foo[`${every}`](function() {})", parserOptions: { ecmaVersion: 6 } }, | ||
{ code: "foo.every(() => true)", parserOptions: { ecmaVersion: 6 } }, | ||
|
||
// options: { allowImplicit: false } | ||
{ code: "foo.every(() => { return true; })", parserOptions: { ecmaVersion: 6 } }, | ||
"foo.every(function() { if (a) return true; else return false; })", | ||
"foo.every(function() { switch (a) { case 0: bar(); default: return true; } })", | ||
"foo.every(function() { try { bar(); return true; } catch (err) { return false; } })", | ||
"foo.every(function() { try { bar(); } finally { return true; } })", | ||
|
||
// options: { allowImplicit: true } | ||
{ code: "foo.every(() => { return; })", options, parserOptions: { ecmaVersion: 6 } }, | ||
{ code: "foo.every(function() { if (a) return; else return; })", options }, | ||
{ code: "foo.every(function() { switch (a) { case 0: bar(); default: return; } })", options }, | ||
{ code: "foo.every(function() { try { bar(); return; } catch (err) { return; } })", options }, | ||
{ code: "foo.every(function() { try { bar(); } finally { return; } })", options }, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please add more invalid tests, e.g: { code: "foo.some(function() {})", errors: [error] },
{ code: "foo.some(function() {})", options, errors: [error] }, |
||
"foo.every(function(){}())", | ||
"foo.every(function(){ return function() { return true; }; }())", | ||
"foo.every(function(){ return function() { return; }; })", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Can
undefined
andreturn;
be wrapped in backticks so it's clear that they're code snippets? Also,return
probably doesn't need the semicolon.