eslint-plugin-promise
Advanced tools
Comparing version 3.8.0 to 4.0.0
@@ -0,10 +1,20 @@ | ||
## 4.0.0 | ||
- Added fixer for `promise/no-new-statics` rule | ||
([#133](https://github.com/xjamundx/eslint-plugin-promise/pull/133)) | ||
- Support ESLint v5 | ||
([#144](https://github.com/xjamundx/eslint-plugin-promise/pull/144)) | ||
This is a breaking change that drops support for Node v4. In order to use ESLint | ||
v5 and eslint-plugin-promise v4, you must use Node >=6. | ||
## 3.8.0 | ||
* Removed `promise/avoid-new` from recommended configuration | ||
- 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` | ||
- 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` | ||
- 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` | ||
- Added docs for `promise/no-nesting` and `promise/prefer-await-to-then` | ||
([#120](https://github.com/xjamundx/eslint-plugin-promise/pull/120)) | ||
@@ -15,9 +25,9 @@ ([#121](https://github.com/xjamundx/eslint-plugin-promise/pull/121)) | ||
* Added `promise/valid-params` rule | ||
- Added `promise/valid-params` rule | ||
([#85](https://github.com/xjamundx/eslint-plugin-promise/pull/85)) | ||
* Added `promise/no-new-statics` rule | ||
- Added `promise/no-new-statics` rule | ||
([#82](https://github.com/xjamundx/eslint-plugin-promise/pull/82)) | ||
* Added fixer for `promise/param-names` rule | ||
- Added fixer for `promise/param-names` rule | ||
([#99](https://github.com/xjamundx/eslint-plugin-promise/pull/99)) | ||
* Added rule documentation to each rule | ||
- Added rule documentation to each rule | ||
([#91](https://github.com/xjamundx/eslint-plugin-promise/pull/91)) | ||
@@ -27,11 +37,11 @@ | ||
* Added `['catch']` support in `catch-or-return` | ||
* Added `no-return-in-finally` rule | ||
* Fixed some formatting in the docs | ||
* Added `allowReject` option to `no-return-wrap` | ||
* Added exceptions for `no-callback-in-promise` | ||
- Added `['catch']` support in `catch-or-return` | ||
- Added `no-return-in-finally` rule | ||
- Fixed some formatting in the docs | ||
- Added `allowReject` option to `no-return-wrap` | ||
- Added exceptions for `no-callback-in-promise` | ||
## 3.5.0 | ||
* Added support for recommended settings using | ||
- Added support for recommended settings using | ||
`extends: plugin:promise/recommended` | ||
@@ -41,87 +51,87 @@ | ||
* Fixed always return false positive with ternary (#31) | ||
- Fixed always return false positive with ternary (#31) | ||
## 3.4.1 | ||
* fixed #49 | ||
- fixed #49 | ||
## 3.4.0 | ||
* new rule: avoid-new | ||
* new rule: no-promise-in-callback | ||
* new rule: no-callback-in-promise | ||
* new rule: no-nesting | ||
- new rule: avoid-new | ||
- new rule: no-promise-in-callback | ||
- new rule: no-callback-in-promise | ||
- new rule: no-nesting | ||
## 3.3.2 | ||
* Removed eslint from peerDeps | ||
- Removed eslint from peerDeps | ||
## 3.3.1 | ||
* Updated engines with proper stuff | ||
* Fixed bug for unreachable code | ||
- Updated engines with proper stuff | ||
- Fixed bug for unreachable code | ||
## 3.3.0 | ||
* Rule: `prefer-async-to-callbacks` added | ||
* Rule: `prefer-async-to-then` added | ||
- Rule: `prefer-async-to-callbacks` added | ||
- Rule: `prefer-async-to-then` added | ||
## 3.2.1 | ||
* Fix: `no-return-wrap` rule missing from index.js | ||
- Fix: `no-return-wrap` rule missing from index.js | ||
## 3.2.0 | ||
* Added `no-return-wrap` rule | ||
- Added `no-return-wrap` rule | ||
## 3.1.0 | ||
* Added multiple terminationMethods | ||
- Added multiple terminationMethods | ||
## 3.0.1 | ||
* Removed deprecated `always-catch` rule | ||
* FIX: always-return error with "fn && fn()" | ||
- Removed deprecated `always-catch` rule | ||
- FIX: always-return error with "fn && fn()" | ||
## 3.0.0 | ||
* Updated column and line numbers | ||
* Added flow analysis for better handling of if statements | ||
- Updated column and line numbers | ||
- Added flow analysis for better handling of if statements | ||
## 2.0.1 | ||
* Fixed type in docs | ||
- Fixed type in docs | ||
## 2.0.0 | ||
* ESLint 3.0 Support | ||
- ESLint 3.0 Support | ||
## 1.3.2 | ||
* Updated tests to run on eslint 2.0 | ||
* Fixed some issues with `no-native` rule | ||
- Updated tests to run on eslint 2.0 | ||
- Fixed some issues with `no-native` rule | ||
## 1.3.1 | ||
* Actually added `no-native` rule | ||
- Actually added `no-native` rule | ||
## 1.3.0 | ||
* Added `no-native` rule | ||
- Added `no-native` rule | ||
## 1.2.0 | ||
* Allow `throw` in `always-return` rule | ||
* Added `terminationMethod` option to `catch-or-return` rule | ||
- Allow `throw` in `always-return` rule | ||
- Added `terminationMethod` option to `catch-or-return` rule | ||
## 1.1.0 | ||
* Added `catch-or-return` rule | ||
- Added `catch-or-return` rule | ||
## 1.0.8 | ||
* Fixed crash issues | ||
- Fixed crash issues | ||
## 1.0.0 - 1.0.7 | ||
* Lots of basic feature updates and doc changes | ||
- Lots of basic feature updates and doc changes |
{ | ||
"name": "eslint-plugin-promise", | ||
"version": "3.8.0", | ||
"version": "4.0.0", | ||
"description": "Enforce best practices for JavaScript promises", | ||
@@ -17,24 +17,20 @@ "keywords": [ | ||
"test": "jest", | ||
"lint": "eslint index.js rules __tests__ --ignore-pattern '**/*.json'" | ||
"lint": "eslint rules __tests__ index.js" | ||
}, | ||
"devDependencies": { | ||
"doctoc": "^1.3.0", | ||
"eslint": "^4.17.0", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-config-standard": "^11.0.0-beta.0", | ||
"eslint": "^5.3.0", | ||
"eslint-config-prettier": "^3.0.1", | ||
"eslint-plugin-eslint-plugin": "^1.4.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jest": "^21.12.2", | ||
"eslint-plugin-node": "^6.0.0", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"eslint-plugin-promise": "./", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"eslint-plugin-jest": "^21.21.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-prettier": "^2.6.2", | ||
"husky": "^0.14.3", | ||
"jest": "^22.4.2", | ||
"jest-runner-eslint": "^0.4.0", | ||
"lint-staged": "^6.1.0", | ||
"prettier": "^1.10.2" | ||
"jest": "^23.5.0", | ||
"jest-runner-eslint": "^0.6.0", | ||
"lint-staged": "^7.2.2", | ||
"prettier": "^1.14.2" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6" | ||
}, | ||
@@ -49,4 +45,11 @@ "license": "ISC", | ||
], | ||
"*.js": ["prettier --write", "eslint --fix", "git add"], | ||
"*.+(json|md)": ["prettier --write", "git add"] | ||
"*.js": [ | ||
"prettier --write", | ||
"eslint --fix", | ||
"git add" | ||
], | ||
"*.+(json|md)": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
} | ||
@@ -53,0 +56,0 @@ }, |
@@ -7,14 +7,12 @@ # eslint-plugin-promise | ||
[![npm version](https://badge.fury.io/js/eslint-plugin-promise.svg)](https://www.npmjs.com/package/eslint-plugin-promise) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
* [Installation](#installation) | ||
* [Usage](#usage) | ||
* [Rules](#rules) | ||
* [Maintainers](#maintainers) | ||
* [License](#license) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Rules](#rules) | ||
- [Maintainers](#maintainers) | ||
- [License](#license) | ||
@@ -42,4 +40,4 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
Add `promise` to the plugins section of your `.eslintrc` configuration file. You | ||
can omit the `eslint-plugin-` prefix: | ||
Add `promise` to the plugins section of your `.eslintrc.json` configuration | ||
file. You can omit the `eslint-plugin-` prefix: | ||
@@ -73,3 +71,3 @@ ```json | ||
or start with the recommended rule set | ||
or start with the recommended rule set: | ||
@@ -88,3 +86,3 @@ ```json | ||
| [`no-return-wrap`][no-return-wrap] | Avoid wrapping values in `Promise.resolve` or `Promise.reject` when not needed. | :bangbang: | | | ||
| [`param-names`][param-names] | Enforce consistent param names when creating new promises. | :bangbang: | :wrench: | | ||
| [`param-names`][param-names] | Enforce consistent param names and ordering when creating new promises. | :bangbang: | :wrench: | | ||
| [`always-return`][always-return] | Return inside each `then()` to create readable and reusable Promise chains. | :bangbang: | | | ||
@@ -96,3 +94,3 @@ | [`no-native`][no-native] | In an ES5 environment, make sure to create a `Promise` constructor before using. | | | | ||
| [`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: | | | ||
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | :wrench: | | ||
| [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | | | ||
@@ -114,9 +112,9 @@ | [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | | | ||
* Jamund Ferguson - [@xjamundx][] | ||
* Macklin Underdown - [@macklinu][] | ||
- Jamund Ferguson - [@xjamundx][] | ||
- Macklin Underdown - [@macklinu][] | ||
## License | ||
* (c) MMXV jden <mailto:jason@denizac.org> - ISC license. | ||
* (c) 2016 Jamund Ferguson <mailto:jamund@gmail.com> - ISC license. | ||
- (c) MMXV jden <mailto:jason@denizac.org> - ISC license. | ||
- (c) 2016 Jamund Ferguson <mailto:jamund@gmail.com> - ISC license. | ||
@@ -123,0 +121,0 @@ [catch-or-return]: docs/rules/catch-or-return.md |
@@ -63,3 +63,3 @@ 'use strict' | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
// funcInfoStack is a stack representing the stack of currently executing | ||
@@ -109,9 +109,9 @@ // functions | ||
onCodePathSegmentStart: function(segment, node) { | ||
onCodePathSegmentStart(segment, node) { | ||
const funcInfo = peek(funcInfoStack) | ||
funcInfo.branchIDStack.push(segment.id) | ||
funcInfo.branchInfoMap[segment.id] = { good: false, node: node } | ||
funcInfo.branchInfoMap[segment.id] = { good: false, node } | ||
}, | ||
onCodePathSegmentEnd: function(segment, node) { | ||
onCodePathSegmentEnd() { | ||
const funcInfo = peek(funcInfoStack) | ||
@@ -121,3 +121,3 @@ funcInfo.branchIDStack.pop() | ||
onCodePathStart: function(path, node) { | ||
onCodePathStart() { | ||
funcInfoStack.push({ | ||
@@ -129,3 +129,3 @@ branchIDStack: [], | ||
onCodePathEnd: function(path, node) { | ||
onCodePathEnd(path, node) { | ||
const funcInfo = funcInfoStack.pop() | ||
@@ -132,0 +132,0 @@ |
@@ -16,5 +16,5 @@ /** | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
return { | ||
NewExpression: function(node) { | ||
NewExpression(node) { | ||
if (node.callee.name === 'Promise') { | ||
@@ -21,0 +21,0 @@ context.report({ node, message: 'Avoid creating new promises.' }) |
@@ -16,5 +16,8 @@ /** | ||
url: getDocsUrl('catch-or-return') | ||
}, | ||
messages: { | ||
terminationMethod: 'Expected {{ terminationMethod }}() or return' | ||
} | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
const options = context.options[0] || {} | ||
@@ -29,3 +32,3 @@ const allowThen = options.allowThen | ||
return { | ||
ExpressionStatement: function(node) { | ||
ExpressionStatement(node) { | ||
if (!isPromise(node.expression)) { | ||
@@ -67,3 +70,3 @@ return | ||
node, | ||
message: 'Expected {{ terminationMethod }}() or return', | ||
messageId: 'terminationMethod', | ||
data: { terminationMethod } | ||
@@ -70,0 +73,0 @@ }) |
@@ -7,9 +7,9 @@ 'use strict' | ||
for (let i = 0; i < exceptions.length; i++) { | ||
callbacks = callbacks.filter(function(item) { | ||
callbacks = callbacks.filter(item => { | ||
return item !== exceptions[i] | ||
}) | ||
} | ||
return callbacks.some(function(trueCallbackName) { | ||
return callbacks.some(trueCallbackName => { | ||
return potentialCallbackName === trueCallbackName | ||
}) | ||
} |
@@ -17,7 +17,10 @@ /** | ||
url: getDocsUrl('no-callback-in-promise') | ||
}, | ||
messages: { | ||
callback: 'Avoid calling back inside of a promise.' | ||
} | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
return { | ||
CallExpression: function(node) { | ||
CallExpression(node) { | ||
const options = context.options[0] || {} | ||
@@ -39,3 +42,3 @@ const exceptions = options.exceptions || [] | ||
node: node.arguments[0], | ||
message: 'Avoid calling back inside of a promise.' | ||
messageId: 'callback' | ||
}) | ||
@@ -49,3 +52,3 @@ } | ||
node, | ||
message: 'Avoid calling back inside of a promise.' | ||
messageId: 'callback' | ||
}) | ||
@@ -52,0 +55,0 @@ } |
@@ -9,3 +9,3 @@ // Borrowed from here: | ||
function isDeclared(scope, ref) { | ||
return scope.variables.some(function(variable) { | ||
return scope.variables.some(variable => { | ||
if (variable.name !== ref.identifier.name) { | ||
@@ -27,7 +27,8 @@ return false | ||
url: getDocsUrl('no-native') | ||
}, | ||
messages: { | ||
name: '"{{name}}" is not defined.' | ||
} | ||
}, | ||
create: function(context) { | ||
const MESSAGE = '"{{name}}" is not defined.' | ||
create(context) { | ||
/** | ||
@@ -41,6 +42,6 @@ * Checks for and reports reassigned constants | ||
return { | ||
'Program:exit': function() { | ||
'Program:exit'() { | ||
const scope = context.getScope() | ||
scope.implicit.left.forEach(function(ref) { | ||
scope.implicit.left.forEach(ref => { | ||
if (ref.identifier.name !== 'Promise') { | ||
@@ -53,3 +54,3 @@ return | ||
node: ref.identifier, | ||
message: MESSAGE, | ||
messageId: 'name', | ||
data: { name: ref.identifier.name } | ||
@@ -56,0 +57,0 @@ }) |
@@ -18,5 +18,5 @@ /** | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
return { | ||
CallExpression: function(node) { | ||
CallExpression(node) { | ||
if (!hasPromiseCallback(node)) return | ||
@@ -23,0 +23,0 @@ if (context.getAncestors().some(isInsidePromise)) { |
@@ -10,3 +10,4 @@ 'use strict' | ||
url: getDocsUrl('no-new-statics') | ||
} | ||
}, | ||
fixable: 'code' | ||
}, | ||
@@ -24,3 +25,9 @@ create(context) { | ||
message: "Avoid calling 'new' on 'Promise.{{ name }}()'", | ||
data: { name: node.callee.property.name } | ||
data: { name: node.callee.property.name }, | ||
fix(fixer) { | ||
return fixer.replaceTextRange( | ||
[node.start, node.start + 'new '.length], | ||
'' | ||
) | ||
} | ||
}) | ||
@@ -27,0 +34,0 @@ } |
@@ -18,5 +18,5 @@ /** | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
return { | ||
CallExpression: function(node) { | ||
CallExpression(node) { | ||
if (!isPromise(node)) return | ||
@@ -23,0 +23,0 @@ |
@@ -12,5 +12,5 @@ 'use strict' | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
return { | ||
CallExpression: function(node) { | ||
CallExpression(node) { | ||
if (isPromise(node)) { | ||
@@ -29,3 +29,3 @@ if ( | ||
if ( | ||
node.arguments[0].body.body.some(function(statement) { | ||
node.arguments[0].body.body.some(statement => { | ||
return statement.type === 'ReturnStatement' | ||
@@ -32,0 +32,0 @@ }) |
@@ -11,9 +11,7 @@ /** | ||
const isPromise = require('./lib/is-promise') | ||
const rejectMessage = 'Expected throw instead of Promise.reject' | ||
const resolveMessage = 'Avoid wrapping return values in Promise.resolve' | ||
function isInPromise(context) { | ||
const expression = context.getAncestors().filter(function(node) { | ||
return node.type === 'ExpressionStatement' | ||
})[0] | ||
const expression = context | ||
.getAncestors() | ||
.filter(node => node.type === 'ExpressionStatement')[0] | ||
return expression && expression.expression && isPromise(expression.expression) | ||
@@ -26,5 +24,9 @@ } | ||
url: getDocsUrl('no-return-wrap') | ||
}, | ||
messages: { | ||
resolve: 'Avoid wrapping return values in Promise.resolve', | ||
reject: 'Expected throw instead of Promise.reject' | ||
} | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
const options = context.options[0] || {} | ||
@@ -34,3 +36,3 @@ const allowReject = options.allowReject | ||
return { | ||
ReturnStatement: function(node) { | ||
ReturnStatement(node) { | ||
if (isInPromise(context)) { | ||
@@ -42,3 +44,3 @@ if (node.argument) { | ||
if (node.argument.callee.property.name === 'resolve') { | ||
context.report({ node, message: resolveMessage }) | ||
context.report({ node, messageId: 'resolve' }) | ||
} else if ( | ||
@@ -48,3 +50,3 @@ !allowReject && | ||
) { | ||
context.report({ node, message: rejectMessage }) | ||
context.report({ node, messageId: 'reject' }) | ||
} | ||
@@ -51,0 +53,0 @@ } |
@@ -5,4 +5,2 @@ 'use strict' | ||
const errorMessage = 'Avoid callbacks. Prefer Async/Await.' | ||
module.exports = { | ||
@@ -12,2 +10,5 @@ meta: { | ||
url: getDocsUrl('prefer-await-to-callbacks') | ||
}, | ||
messages: { | ||
error: 'Avoid callbacks. Prefer Async/Await.' | ||
} | ||
@@ -19,3 +20,3 @@ }, | ||
if (lastParam.name === 'callback' || lastParam.name === 'cb') { | ||
context.report({ node: lastParam, message: errorMessage }) | ||
context.report({ node: lastParam, messageId: 'error' }) | ||
} | ||
@@ -34,3 +35,3 @@ } | ||
if (node.callee.name === 'cb' || node.callee.name === 'callback') { | ||
context.report({ node, message: errorMessage }) | ||
context.report({ node, messageId: 'error' }) | ||
return | ||
@@ -57,3 +58,3 @@ } | ||
if (!isInsideYieldOrAwait()) { | ||
context.report({ node: arg, message: errorMessage }) | ||
context.report({ node: arg, messageId: 'error' }) | ||
} | ||
@@ -60,0 +61,0 @@ } |
@@ -16,3 +16,3 @@ /** | ||
}, | ||
create: function(context) { | ||
create(context) { | ||
/** Returns true if node is inside yield or await expression. */ | ||
@@ -37,3 +37,3 @@ function isInsideYieldOrAwait() { | ||
return { | ||
MemberExpression: function(node) { | ||
MemberExpression(node) { | ||
if (isTopLevelScoped() || isInsideYieldOrAwait()) { | ||
@@ -40,0 +40,0 @@ return |
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
37282
12
879
26
133