Socket
Socket
Sign inDemoInstall

eslint-plugin-promise

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-promise - npm Package Compare versions

Comparing version 3.7.0 to 3.8.0

.prettierignore

12

CHANGELOG.md

@@ -0,1 +1,13 @@

## 3.8.0
* Removed `promise/avoid-new` from recommended configuration
([#119](https://github.com/xjamundx/eslint-plugin-promise/pull/119))
* Ignored event listener callbacks in `promise/prefer-await-to-callbacks`
([#117](https://github.com/xjamundx/eslint-plugin-promise/pull/117))
* Ignored top-level awaits in `promise/prefer-await-to-then`
([#126](https://github.com/xjamundx/eslint-plugin-promise/pull/126))
* Added docs for `promise/no-nesting` and `promise/prefer-await-to-then`
([#120](https://github.com/xjamundx/eslint-plugin-promise/pull/120))
([#121](https://github.com/xjamundx/eslint-plugin-promise/pull/121))
## 3.7.0

@@ -2,0 +14,0 @@

2

index.js

@@ -38,3 +38,3 @@ 'use strict'

'promise/no-callback-in-promise': 'warn',
'promise/avoid-new': 'warn',
'promise/avoid-new': 'off',
'promise/no-new-statics': 'error',

@@ -41,0 +41,0 @@ 'promise/no-return-in-finally': 'warn',

{
"name": "eslint-plugin-promise",
"version": "3.7.0",
"version": "3.8.0",
"description": "Enforce best practices for JavaScript promises",

@@ -5,0 +5,0 @@ "keywords": [

@@ -91,3 +91,3 @@ # eslint-plugin-promise

| [`no-callback-in-promise`][no-callback-in-promise] | Avoid calling `cb()` inside of a `then()` (use [nodeify][] instead) | :warning: | |
| [`avoid-new` ][avoid-new] | Avoid creating `new` promises outside of utility libs (use [pify][] instead) | :warning: | |
| [`avoid-new`][avoid-new] | Avoid creating `new` promises outside of utility libs (use [pify][] instead) | | |
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | |

@@ -94,0 +94,0 @@ | [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |

@@ -32,3 +32,3 @@ /**

expression.callee.object.name === 'Promise' &&
PROMISE_STATICS.indexOf(expression.callee.property.name) !== -1)
PROMISE_STATICS[expression.callee.property.name])
)

@@ -35,0 +35,0 @@ }

'use strict'
module.exports = ['all', 'race', 'reject', 'resolve']
module.exports = {
all: true,
race: true,
reject: true,
resolve: true
}

@@ -18,3 +18,3 @@ 'use strict'

node.callee.object.name === 'Promise' &&
PROMISE_STATICS.indexOf(node.callee.property.name) > -1
PROMISE_STATICS[node.callee.property.name]
) {

@@ -21,0 +21,0 @@ context.report({

@@ -1,6 +0,1 @@

/**
* Rule: prefer-await-to-callbacks
* Discourage using then() and instead use async/await.
*/
'use strict'

@@ -18,10 +13,6 @@

},
create: function(context) {
create(context) {
function checkLastParamsForCallback(node) {
const len = node.params.length - 1
const lastParam = node.params[len]
if (
lastParam &&
(lastParam.name === 'callback' || lastParam.name === 'cb')
) {
const lastParam = node.params[node.params.length - 1] || {}
if (lastParam.name === 'callback' || lastParam.name === 'cb') {
context.report({ node: lastParam, message: errorMessage })

@@ -31,3 +22,3 @@ }

function isInsideYieldOrAwait() {
return context.getAncestors().some(function(parent) {
return context.getAncestors().some(parent => {
return (

@@ -39,4 +30,4 @@ parent.type === 'AwaitExpression' || parent.type === 'YieldExpression'

return {
CallExpression: function(node) {
// callbacks aren't allowed
CallExpression(node) {
// Callbacks aren't allowed.
if (node.callee.name === 'cb' || node.callee.name === 'callback') {

@@ -47,6 +38,6 @@ context.report({ node, message: errorMessage })

// thennables aren't allowed either
// Then-ables aren't allowed either.
const args = node.arguments
const num = args.length - 1
const arg = num > -1 && node.arguments && node.arguments[num]
const lastArgIndex = args.length - 1
const arg = lastArgIndex > -1 && node.arguments[lastArgIndex]
if (

@@ -56,2 +47,10 @@ (arg && arg.type === 'FunctionExpression') ||

) {
// Ignore event listener callbacks.
if (
node.callee.property &&
(node.callee.property.name === 'on' ||
node.callee.property.name === 'once')
) {
return
}
if (arg.params && arg.params[0] && arg.params[0].name === 'err') {

@@ -58,0 +57,0 @@ if (!isInsideYieldOrAwait()) {

@@ -17,13 +17,23 @@ /**

create: function(context) {
/** Returns true if node is inside yield or await expression. */
function isInsideYieldOrAwait() {
return context.getAncestors().some(parent => {
return (
parent.type === 'AwaitExpression' || parent.type === 'YieldExpression'
)
})
}
/**
* Returns true if node is created at the top-level scope.
* Await statements are not allowed at the top level,
* only within function declarations.
*/
function isTopLevelScoped() {
return context.getScope().block.type === 'Program'
}
return {
MemberExpression: function(node) {
// you can then() if you are inside of a yield or await
if (
context.getAncestors().some(function(parent) {
return (
parent.type === 'AwaitExpression' ||
parent.type === 'YieldExpression'
)
})
) {
if (isTopLevelScoped() || isInsideYieldOrAwait()) {
return

@@ -30,0 +40,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc