eslint-plugin-promise
Advanced tools
Comparing version
@@ -0,1 +1,11 @@ | ||
## 4.3.0 | ||
- https://github.com/xjamundx/eslint-plugin-promise/pull/202 | ||
- Udpated jest | ||
## 4.2.2 | ||
- Added license | ||
- Dependabot security updates | ||
## 4.2.1 | ||
@@ -2,0 +12,0 @@ |
12
index.js
@@ -18,3 +18,3 @@ 'use strict' | ||
'no-return-in-finally': require('./rules/no-return-in-finally'), | ||
'valid-params': require('./rules/valid-params') | ||
'valid-params': require('./rules/valid-params'), | ||
}, | ||
@@ -26,3 +26,3 @@ rulesConfig: { | ||
'no-native': 0, | ||
'catch-or-return': 1 | ||
'catch-or-return': 1, | ||
}, | ||
@@ -44,6 +44,6 @@ configs: { | ||
'promise/no-return-in-finally': 'warn', | ||
'promise/valid-params': 'warn' | ||
} | ||
} | ||
} | ||
'promise/valid-params': 'warn', | ||
}, | ||
}, | ||
}, | ||
} |
{ | ||
"name": "eslint-plugin-promise", | ||
"version": "4.2.1", | ||
"version": "4.3.1", | ||
"description": "Enforce best practices for JavaScript promises", | ||
@@ -13,21 +13,28 @@ "keywords": [ | ||
"author": "jden <jason@denizac.org>", | ||
"repository": "git@github.com:xjamundx/eslint-plugin-promise.git", | ||
"contributors": [ | ||
"Brett Zamir" | ||
], | ||
"repository": "https://github.com/xjamundx/eslint-plugin-promise", | ||
"homepage": "https://github.com/xjamundx/eslint-plugin-promise", | ||
"bugs": "https://github.com/xjamundx/eslint-plugin-promise/issues", | ||
"scripts": { | ||
"precommit": "lint-staged", | ||
"precommit": "lint-staged --concurrent false", | ||
"test": "jest", | ||
"lint": "eslint rules __tests__ index.js" | ||
"lint": "eslint rules __tests__ index.js", | ||
"format": "prettier --write '**/*.js'" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"doctoc": "^1.3.0", | ||
"eslint": "^5.16.0", | ||
"doctoc": "^1.4.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^3.0.1", | ||
"eslint-plugin-eslint-plugin": "^1.4.0", | ||
"eslint-plugin-jest": "^21.21.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-eslint-plugin": "^2.2.1", | ||
"eslint-plugin-jest": "^23.13.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^2.6.2", | ||
"husky": "^0.14.3", | ||
"jest": "^24.5.0", | ||
"jest-runner-eslint": "^0.7.3", | ||
"lint-staged": "^7.2.2", | ||
"prettier": "^1.14.2" | ||
"husky": "^4.2.5", | ||
"jest": "^26.6.3", | ||
"jest-runner-eslint": "^0.8.0", | ||
"lint-staged": "^10.2.4", | ||
"prettier": "^2.2.1" | ||
}, | ||
@@ -39,18 +46,12 @@ "engines": { | ||
"lint-staged": { | ||
"concurrent": false, | ||
"linters": { | ||
"{README.md,CONTRIBUTING.md}": [ | ||
"doctoc --maxlevel 3 --notitle", | ||
"git add" | ||
], | ||
"*.js": [ | ||
"prettier --write", | ||
"eslint --fix", | ||
"git add" | ||
], | ||
"*.+(json|md)": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
} | ||
"{README.md,CONTRIBUTING.md}": [ | ||
"doctoc --maxlevel 3 --notitle" | ||
], | ||
"*.js": [ | ||
"prettier --write", | ||
"eslint --fix" | ||
], | ||
"*.+(json|md)": [ | ||
"prettier --write" | ||
] | ||
}, | ||
@@ -57,0 +58,0 @@ "prettier": { |
@@ -59,5 +59,6 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
url: getDocsUrl('always-return') | ||
} | ||
url: getDocsUrl('always-return'), | ||
}, | ||
}, | ||
@@ -72,3 +73,3 @@ create(context) { | ||
// funcInfoStack[i].branchInfoMap[j].good is a boolean representing whether | ||
// the given branch explictly `return`s or `throw`s. It starts as `false` | ||
// the given branch explicitly `return`s or `throw`s. It starts as `false` | ||
// for every branch and is updated to `true` if a `return` or `throw` | ||
@@ -124,3 +125,3 @@ // statement is found | ||
branchIDStack: [], | ||
branchInfoMap: {} | ||
branchInfoMap: {}, | ||
}) | ||
@@ -136,3 +137,3 @@ }, | ||
path.finalSegments.forEach(segment => { | ||
path.finalSegments.forEach((segment) => { | ||
const id = segment.id | ||
@@ -154,9 +155,9 @@ const branch = funcInfo.branchInfoMap[id] | ||
message: 'Each then() should return a value or throw', | ||
node: branch.node | ||
node: branch.node, | ||
}) | ||
} | ||
}) | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -12,5 +12,6 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('avoid-new') | ||
} | ||
url: getDocsUrl('avoid-new'), | ||
}, | ||
}, | ||
@@ -23,5 +24,5 @@ create(context) { | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -14,8 +14,9 @@ /** | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
url: getDocsUrl('catch-or-return') | ||
url: getDocsUrl('catch-or-return'), | ||
}, | ||
messages: { | ||
terminationMethod: 'Expected {{ terminationMethod }}() or return' | ||
} | ||
terminationMethod: 'Expected {{ terminationMethod }}() or return', | ||
}, | ||
}, | ||
@@ -91,7 +92,7 @@ create(context) { | ||
messageId: 'terminationMethod', | ||
data: { terminationMethod } | ||
data: { terminationMethod }, | ||
}) | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
'use strict' | ||
const pkg = require('../../package') | ||
const REPO_URL = 'https://github.com/xjamundx/eslint-plugin-promise' | ||
@@ -16,5 +14,5 @@ | ||
function getDocsUrl(ruleName) { | ||
return `${REPO_URL}/tree/v${pkg.version}/docs/rules/${ruleName}.md` | ||
return `${REPO_URL}/blob/master/docs/rules/${ruleName}.md` | ||
} | ||
module.exports = getDocsUrl |
/** | ||
* Library: Has Promis eCallback | ||
* Library: Has Promise Callback | ||
* Makes sure that an Expression node is part of a promise | ||
@@ -4,0 +4,0 @@ * with callback functions (like then() or catch()) |
@@ -7,9 +7,9 @@ 'use strict' | ||
for (let i = 0; i < exceptions.length; i++) { | ||
callbacks = callbacks.filter(item => { | ||
callbacks = callbacks.filter((item) => { | ||
return item !== exceptions[i] | ||
}) | ||
} | ||
return callbacks.some(trueCallbackName => { | ||
return callbacks.some((trueCallbackName) => { | ||
return potentialCallbackName === trueCallbackName | ||
}) | ||
} |
@@ -7,3 +7,3 @@ 'use strict' | ||
reject: true, | ||
resolve: true | ||
resolve: true, | ||
} |
@@ -15,8 +15,9 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('no-callback-in-promise') | ||
url: getDocsUrl('no-callback-in-promise'), | ||
}, | ||
messages: { | ||
callback: 'Avoid calling back inside of a promise.' | ||
} | ||
callback: 'Avoid calling back inside of a promise.', | ||
}, | ||
}, | ||
@@ -42,3 +43,3 @@ create(context) { | ||
node: node.arguments[0], | ||
messageId: 'callback' | ||
messageId: 'callback', | ||
}) | ||
@@ -52,8 +53,8 @@ } | ||
node, | ||
messageId: 'callback' | ||
messageId: 'callback', | ||
}) | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -9,3 +9,3 @@ // Borrowed from here: | ||
function isDeclared(scope, ref) { | ||
return scope.variables.some(variable => { | ||
return scope.variables.some((variable) => { | ||
if (variable.name !== ref.identifier.name) { | ||
@@ -25,8 +25,9 @@ return false | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('no-native') | ||
url: getDocsUrl('no-native'), | ||
}, | ||
messages: { | ||
name: '"{{name}}" is not defined.' | ||
} | ||
name: '"{{name}}" is not defined.', | ||
}, | ||
}, | ||
@@ -45,3 +46,3 @@ create(context) { | ||
scope.implicit.left.forEach(ref => { | ||
scope.implicit.left.forEach((ref) => { | ||
if (ref.identifier.name !== 'Promise') { | ||
@@ -55,9 +56,9 @@ return | ||
messageId: 'name', | ||
data: { name: ref.identifier.name } | ||
data: { name: ref.identifier.name }, | ||
}) | ||
} | ||
}) | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -14,5 +14,6 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('no-nesting') | ||
} | ||
url: getDocsUrl('no-nesting'), | ||
}, | ||
}, | ||
@@ -26,5 +27,5 @@ create(context) { | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -8,6 +8,7 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
url: getDocsUrl('no-new-statics') | ||
url: getDocsUrl('no-new-statics'), | ||
}, | ||
fixable: 'code' | ||
fixable: 'code', | ||
}, | ||
@@ -31,8 +32,8 @@ create(context) { | ||
) | ||
} | ||
}, | ||
}) | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -14,5 +14,6 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('no-promise-in-callback') | ||
} | ||
url: getDocsUrl('no-promise-in-callback'), | ||
}, | ||
}, | ||
@@ -34,8 +35,8 @@ create(context) { | ||
node: node.callee, | ||
message: 'Avoid using promises inside of callbacks.' | ||
message: 'Avoid using promises inside of callbacks.', | ||
}) | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -8,5 +8,6 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
url: getDocsUrl('no-return-in-finally') | ||
} | ||
url: getDocsUrl('no-return-in-finally'), | ||
}, | ||
}, | ||
@@ -29,3 +30,3 @@ create(context) { | ||
if ( | ||
node.arguments[0].body.body.some(statement => { | ||
node.arguments[0].body.body.some((statement) => { | ||
return statement.type === 'ReturnStatement' | ||
@@ -36,3 +37,3 @@ }) | ||
node: node.callee.property, | ||
message: 'No return in finally' | ||
message: 'No return in finally', | ||
}) | ||
@@ -43,5 +44,5 @@ } | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
/** | ||
* Rule: no-return-wrap function | ||
* Prevents uneccessary wrapping of results in Promise.resolve | ||
* Prevents unnecessary wrapping of results in Promise.resolve | ||
* or Promise.reject as the Promise will do that for us | ||
@@ -15,3 +15,3 @@ */ | ||
.getAncestors() | ||
.filter(node => { | ||
.filter((node) => { | ||
return ( | ||
@@ -41,9 +41,10 @@ node.type === 'ArrowFunctionExpression' || | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('no-return-wrap') | ||
url: getDocsUrl('no-return-wrap'), | ||
}, | ||
messages: { | ||
resolve: 'Avoid wrapping return values in Promise.resolve', | ||
reject: 'Expected throw instead of Promise.reject' | ||
} | ||
reject: 'Expected throw instead of Promise.reject', | ||
}, | ||
}, | ||
@@ -54,25 +55,32 @@ create(context) { | ||
/** | ||
* Checks a call expression, reporting if necessary. | ||
* @param callExpression The call expression. | ||
* @param node The node to report. | ||
*/ | ||
function checkCallExpression({ callee }, node) { | ||
if ( | ||
isInPromise(context) && | ||
callee.type === 'MemberExpression' && | ||
callee.object.name === 'Promise' | ||
) { | ||
if (callee.property.name === 'resolve') { | ||
context.report({ node, messageId: 'resolve' }) | ||
} else if (!allowReject && callee.property.name === 'reject') { | ||
context.report({ node, messageId: 'reject' }) | ||
} | ||
} | ||
} | ||
return { | ||
ReturnStatement(node) { | ||
if (isInPromise(context)) { | ||
if (node.argument) { | ||
if (node.argument.type === 'CallExpression') { | ||
if (node.argument.callee.type === 'MemberExpression') { | ||
if (node.argument.callee.object.name === 'Promise') { | ||
if (node.argument.callee.property.name === 'resolve') { | ||
context.report({ node, messageId: 'resolve' }) | ||
} else if ( | ||
!allowReject && | ||
node.argument.callee.property.name === 'reject' | ||
) { | ||
context.report({ node, messageId: 'reject' }) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (node.argument && node.argument.type === 'CallExpression') { | ||
checkCallExpression(node.argument, node) | ||
} | ||
} | ||
}, | ||
'ArrowFunctionExpression > CallExpression'(node) { | ||
checkCallExpression(node, node) | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -7,6 +7,6 @@ 'use strict' | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('param-names') | ||
url: getDocsUrl('param-names'), | ||
}, | ||
fixable: 'code' | ||
}, | ||
@@ -30,9 +30,9 @@ create(context) { | ||
message: | ||
'Promise constructor parameters must be named resolve, reject' | ||
'Promise constructor parameters must be named resolve, reject', | ||
}) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -7,8 +7,9 @@ 'use strict' | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('prefer-await-to-callbacks') | ||
url: getDocsUrl('prefer-await-to-callbacks'), | ||
}, | ||
messages: { | ||
error: 'Avoid callbacks. Prefer Async/Await.' | ||
} | ||
error: 'Avoid callbacks. Prefer Async/Await.', | ||
}, | ||
}, | ||
@@ -23,3 +24,3 @@ create(context) { | ||
function isInsideYieldOrAwait() { | ||
return context.getAncestors().some(parent => { | ||
return context.getAncestors().some((parent) => { | ||
return ( | ||
@@ -54,3 +55,7 @@ parent.type === 'AwaitExpression' || parent.type === 'YieldExpression' | ||
} | ||
if (arg.params && arg.params[0] && arg.params[0].name === 'err') { | ||
if ( | ||
arg.params && | ||
arg.params[0] && | ||
(arg.params[0].name === 'err' || arg.params[0].name === 'error') | ||
) { | ||
if (!isInsideYieldOrAwait()) { | ||
@@ -64,5 +69,5 @@ context.report({ node: arg, messageId: 'error' }) | ||
FunctionExpression: checkLastParamsForCallback, | ||
ArrowFunctionExpression: checkLastParamsForCallback | ||
ArrowFunctionExpression: checkLastParamsForCallback, | ||
} | ||
} | ||
}, | ||
} |
@@ -12,5 +12,6 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('prefer-await-to-then') | ||
} | ||
url: getDocsUrl('prefer-await-to-then'), | ||
}, | ||
}, | ||
@@ -20,3 +21,3 @@ create(context) { | ||
function isInsideYieldOrAwait() { | ||
return context.getAncestors().some(parent => { | ||
return context.getAncestors().some((parent) => { | ||
return ( | ||
@@ -47,8 +48,8 @@ parent.type === 'AwaitExpression' || parent.type === 'YieldExpression' | ||
node: node.property, | ||
message: 'Prefer await to then().' | ||
message: 'Prefer await to then().', | ||
}) | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
@@ -8,7 +8,8 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: | ||
'Ensures the proper number of arguments are passed to Promise functions', | ||
url: getDocsUrl('valid-params') | ||
} | ||
url: getDocsUrl('valid-params'), | ||
}, | ||
}, | ||
@@ -33,3 +34,3 @@ create(context) { | ||
'Promise.{{ name }}() requires 0 or 1 arguments, but received {{ numArgs }}', | ||
data: { name, numArgs } | ||
data: { name, numArgs }, | ||
}) | ||
@@ -44,3 +45,3 @@ } | ||
'Promise.{{ name }}() requires 1 or 2 arguments, but received {{ numArgs }}', | ||
data: { name, numArgs } | ||
data: { name, numArgs }, | ||
}) | ||
@@ -58,3 +59,3 @@ } | ||
'Promise.{{ name }}() requires 1 argument, but received {{ numArgs }}', | ||
data: { name, numArgs } | ||
data: { name, numArgs }, | ||
}) | ||
@@ -66,5 +67,5 @@ } | ||
} | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
40190
4.81%28
7.69%933
2.41%0
-100%1
-50%