eslint-plugin-promise
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -29,2 +29,3 @@ 'use strict' | ||
recommended: { | ||
plugins: ['promise'], | ||
rules: { | ||
@@ -31,0 +32,0 @@ 'promise/always-return': 'error', |
{ | ||
"name": "eslint-plugin-promise", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "Enforce best practices for JavaScript promises", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -24,2 +24,3 @@ /** | ||
const allowThen = options.allowThen | ||
const allowFinally = options.allowFinally | ||
let terminationMethod = options.terminationMethod || 'catch' | ||
@@ -31,2 +32,48 @@ | ||
function isAllowedPromiseTermination(expression) { | ||
// somePromise.then(a, b) | ||
if ( | ||
allowThen && | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'then' && | ||
expression.arguments.length === 2 | ||
) { | ||
return true | ||
} | ||
// somePromise.catch().finally(fn) | ||
if ( | ||
allowFinally && | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'finally' && | ||
isPromise(expression.callee.object) && | ||
isAllowedPromiseTermination(expression.callee.object) | ||
) { | ||
return true | ||
} | ||
// somePromise.catch() | ||
if ( | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
terminationMethod.indexOf(expression.callee.property.name) !== -1 | ||
) { | ||
return true | ||
} | ||
// somePromise['catch']() | ||
if ( | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.type === 'Literal' && | ||
expression.callee.property.value === 'catch' | ||
) { | ||
return true | ||
} | ||
return false | ||
} | ||
return { | ||
@@ -38,32 +85,6 @@ ExpressionStatement(node) { | ||
// somePromise.then(a, b) | ||
if ( | ||
allowThen && | ||
node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.name === 'then' && | ||
node.expression.arguments.length === 2 | ||
) { | ||
if (isAllowedPromiseTermination(node.expression)) { | ||
return | ||
} | ||
// somePromise.catch() | ||
if ( | ||
node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
terminationMethod.indexOf(node.expression.callee.property.name) !== -1 | ||
) { | ||
return | ||
} | ||
// somePromise['catch']() | ||
if ( | ||
node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.type === 'Literal' && | ||
node.expression.callee.property.value === 'catch' | ||
) { | ||
return | ||
} | ||
context.report({ | ||
@@ -70,0 +91,0 @@ node, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37704
892