eslint-plugin-promise
Advanced tools
Comparing version 4.2.1 to 4.3.0
{ | ||
"name": "eslint-plugin-promise", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Enforce best practices for JavaScript promises", | ||
@@ -13,20 +13,27 @@ "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", | ||
"husky": "^4.2.5", | ||
"jest": "^26.6.3", | ||
"jest-runner-eslint": "^0.8.0", | ||
"lint-staged": "^10.2.4", | ||
"prettier": "^1.14.2" | ||
@@ -39,18 +46,12 @@ }, | ||
"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,2 +59,3 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
@@ -72,3 +73,3 @@ url: getDocsUrl('always-return') | ||
// 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` | ||
@@ -75,0 +76,0 @@ // statement is found |
@@ -12,2 +12,3 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -14,0 +15,0 @@ url: getDocsUrl('avoid-new') |
@@ -14,2 +14,3 @@ /** | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
@@ -16,0 +17,0 @@ url: getDocsUrl('catch-or-return') |
'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()) |
@@ -15,2 +15,3 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -17,0 +18,0 @@ url: getDocsUrl('no-callback-in-promise') |
@@ -24,2 +24,3 @@ // Borrowed from here: | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -26,0 +27,0 @@ url: getDocsUrl('no-native') |
@@ -14,2 +14,3 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -16,0 +17,0 @@ url: getDocsUrl('no-nesting') |
@@ -8,2 +8,3 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
@@ -10,0 +11,0 @@ url: getDocsUrl('no-new-statics') |
@@ -14,2 +14,3 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -16,0 +17,0 @@ url: getDocsUrl('no-promise-in-callback') |
@@ -8,2 +8,3 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
@@ -10,0 +11,0 @@ url: getDocsUrl('no-return-in-finally') |
/** | ||
* 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 | ||
@@ -40,2 +40,3 @@ */ | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -53,22 +54,29 @@ url: getDocsUrl('no-return-wrap') | ||
/** | ||
* 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) | ||
} | ||
@@ -75,0 +83,0 @@ } |
@@ -7,6 +7,6 @@ 'use strict' | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
url: getDocsUrl('param-names') | ||
}, | ||
fixable: 'code' | ||
} | ||
}, | ||
@@ -13,0 +13,0 @@ create(context) { |
@@ -7,2 +7,3 @@ 'use strict' | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -53,3 +54,7 @@ url: getDocsUrl('prefer-await-to-callbacks') | ||
} | ||
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()) { | ||
@@ -56,0 +61,0 @@ context.report({ node: arg, messageId: 'error' }) |
@@ -12,2 +12,3 @@ /** | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
@@ -14,0 +15,0 @@ url: getDocsUrl('prefer-await-to-then') |
@@ -8,2 +8,3 @@ 'use strict' | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
@@ -10,0 +11,0 @@ description: |
39947
28
933