forked from eslint-community/eslint-plugin-promise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves eslint-community#75
- Loading branch information
Showing
7 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Avoid calling `new` on a Promise static method (e.g. `new Promise.resolve()`) (no-new-statics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = ['all', 'race', 'reject', 'resolve'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict' | ||
|
||
const PROMISE_STATICS = require('./lib/promise-statics') | ||
const getDocsUrl = require('./lib/get-docs-url') | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
url: getDocsUrl('no-new-statics') | ||
} | ||
}, | ||
create(context) { | ||
return { | ||
NewExpression(node) { | ||
if ( | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.name === 'Promise' && | ||
PROMISE_STATICS.indexOf(node.callee.property.name) > -1 | ||
) { | ||
context.report({ | ||
node, | ||
message: 'Avoid calling new on a Promise static method' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const rule = require('../rules/no-new-statics') | ||
const RuleTester = require('eslint').RuleTester | ||
const ruleTester = new RuleTester() | ||
|
||
const message = 'Avoid calling new on a Promise static method' | ||
|
||
ruleTester.run('no-new-statics', rule, { | ||
valid: [ | ||
'Promise.resolve()', | ||
'Promise.reject()', | ||
'Promise.all()', | ||
'Promise.race()', | ||
'new Promise(function (resolve, reject) {})', | ||
'new SomeClass()', | ||
'SomeClass.resolve()', | ||
'new SomeClass.resolve()' | ||
], | ||
invalid: [ | ||
{ code: 'new Promise.resolve()', errors: [{ message }] }, | ||
{ code: 'new Promise.reject()', errors: [{ message }] }, | ||
{ code: 'new Promise.all()', errors: [{ message }] }, | ||
{ code: 'new Promise.race()', errors: [{ message }] } | ||
] | ||
}) |