Skip to content
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

feat(catch-or-return,no-new-statics,no-promise-in-callback,valid-params): add support for Promise.allSettled() & Promise.any() #370

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions __tests__/catch-or-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ ruleTester.run('catch-or-return', rule, {
code: 'Promise.resolve(frank)',
errors: [{ message: catchMessage }],
},
{
code: 'Promise.all([])',
errors: [{ message: catchMessage }],
},
{
code: 'Promise.allSettled([])',
errors: [{ message: catchMessage }],
},
{
code: 'Promise.any([])',
errors: [{ message: catchMessage }],
},
{
code: 'Promise.race([])',
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(to).catch(fn).then(foo)',
errors: [{ message: catchMessage }],
Expand Down
10 changes: 10 additions & 0 deletions __tests__/no-new-statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ ruleTester.run('no-new-statics', rule, {
output: 'Promise.all()',
errors: [{ message: "Avoid calling 'new' on 'Promise.all()'" }],
},
{
code: 'new Promise.allSettled()',
output: 'Promise.allSettled()',
errors: [{ message: "Avoid calling 'new' on 'Promise.allSettled()'" }],
},
{
code: 'new Promise.any()',
output: 'Promise.any()',
errors: [{ message: "Avoid calling 'new' on 'Promise.any()'" }],
},
{
code: 'new Promise.race()',
output: 'Promise.race()',
Expand Down
8 changes: 8 additions & 0 deletions __tests__/no-promise-in-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ ruleTester.run('no-promise-in-callback', rule, {
code: 'function x(err) { Promise.all() }',
errors: [{ message: errorMessage }],
},
{
code: 'function x(err) { Promise.allSettled() }',
errors: [{ message: errorMessage }],
},
{
code: 'function x(err) { Promise.any() }',
errors: [{ message: errorMessage }],
},
{
code: 'let x = (err) => doThingWith(err).then(a)',
errors: [{ message: errorMessage }],
Expand Down
36 changes: 36 additions & 0 deletions __tests__/valid-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ ruleTester.run('valid-params', rule, {
'Promise.all(iterable)',
'Promise.all([one, two, three])',

// valid Promise.allSettled()
'Promise.allSettled([])',
'Promise.allSettled(iterable)',
'Promise.allSettled([one, two, three])',

// valid Promise.any()
'Promise.any([])',
'Promise.any(iterable)',
'Promise.any([one, two, three])',

// valid Promise.then()
'somePromise().then(success)',
'somePromise().then(success, failure)',
Expand Down Expand Up @@ -129,6 +139,32 @@ ruleTester.run('valid-params', rule, {
{ message: 'Promise.all() requires 1 argument, but received 4' },
],
},
// invalid Promise.allSettled()
{
code: 'Promise.allSettled(1, 2, 3)',
errors: [
{ message: 'Promise.allSettled() requires 1 argument, but received 3' },
],
},
{
code: 'Promise.allSettled({}, function() {}, 1, 2)',
errors: [
{ message: 'Promise.allSettled() requires 1 argument, but received 4' },
],
},
// invalid Promise.any()
{
code: 'Promise.any(1, 2, 3)',
errors: [
{ message: 'Promise.any() requires 1 argument, but received 3' },
],
},
{
code: 'Promise.any({}, function() {}, 1, 2)',
errors: [
{ message: 'Promise.any() requires 1 argument, but received 4' },
],
},

// invalid Promise.then()
{
Expand Down
2 changes: 2 additions & 0 deletions rules/lib/promise-statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module.exports = {
all: true,
allSettled: true,
any: true,
race: true,
reject: true,
resolve: true,
Expand Down
2 changes: 2 additions & 0 deletions rules/valid-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module.exports = {
break
case 'race':
case 'all':
case 'allSettled':
case 'any':
case 'catch':
case 'finally':
if (numArgs !== 1) {
Expand Down