-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #75
- Loading branch information
Showing
6 changed files
with
67 additions
and
2 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
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,27 @@ | ||
'use strict' | ||
|
||
const PROMISE_STATICS = require('./lib/promise-statics') | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
url: 'https://github.com/xjamundx/eslint-plugin-promise#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 }] } | ||
] | ||
}) |