npm
npmjs.com › package › eslint-plugin-promise
eslint-plugin-promise - npm
Enforce best practices for JavaScript promises. Latest version: 7.2.1, last published: a year ago. Start using eslint-plugin-promise in your project by running `npm i eslint-plugin-promise`. There are 4879 other projects in the npm registry using eslint-plugin-promise.
» npm install eslint-plugin-promise
Published Nov 27, 2024
Version 7.2.1
Author jden
GitHub
github.com › eslint-community › eslint-plugin-promise
GitHub - eslint-community/eslint-plugin-promise: Enforce best practices for JavaScript promises
Enforce best practices for JavaScript promises. ... Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-promise globally.
Starred by 986 users
Forked by 96 users
Languages JavaScript 100.0% | JavaScript 100.0%
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › CHANGELOG.md
eslint-plugin-promise/CHANGELOG.md at main · eslint-community/eslint-plugin-promise
no-callback-in-promise: false triggering of callback (#574) (8324564) ... deps: switch from dependabot to renovate using shared eslint community configuration (#537) (30efed7) deps: update @eslint-community/eslint-utils to v4.4.1 (#562) (5c3628d) ... 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.
Author eslint-community
GitHub
github.com › eslint-community › eslint-plugin-promise › issues
eslint-community/eslint-plugin-promise
Enforce best practices for JavaScript promises. Contribute to eslint-community/eslint-plugin-promise development by creating an account on GitHub.
Author eslint-community
GitHub
github.com › eslint-community › eslint-plugin-promise › releases
Releases · eslint-community/eslint-plugin-promise
Enforce best practices for JavaScript promises. Contribute to eslint-community/eslint-plugin-promise development by creating an account on GitHub.
Author eslint-community
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › README.md
eslint-plugin-promise/README.md at main · eslint-community/eslint-plugin-promise
You can omit the eslint-plugin- prefix: ... Then configure the rules you want to use under the rules section. { "rules": { "promise/always-return": "error", "promise/no-return-wrap": "error", "promise/param-names": "error", "promise/catch-or-return": "error", "promise/no-native": "off", "promise/no-nesting": "warn", "promise/no-promise-in-callback": "warn", "promise/no-callback-in-promise": "warn", "promise/avoid-new": "warn", "promise/no-new-statics": "error", "promise/no-return-in-finally": "warn", "promise/valid-params": "warn", "promise/no-multiple-resolved": "error" } }
Author eslint-community
Npmdoc
npmdoc.github.io › node-npmdoc-eslint-plugin-promise › build › apidoc.html
function eslint-plugin-promise.rules.avoid-new (context)
create = function (context) { var MESSAGE = '"function eslint-plugin-promise.rules.no-native.create" is not defined.' /** * Checks for and reports reassigned constants * * @param {Scope} scope - an escope Scope object * @returns {void} * @private */ return { 'Program:exit': function () { var scope = context.getScope() scope.implicit.left.forEach(function (ref) { if (ref.identifier.name !== 'Promise') { return } if (!isDeclared(scope, ref)) { context.report(ref.identifier, MESSAGE, { name: ref.identifier.name }) } }) } } }
npm
npmjs.com › package › eslint-plugin-no-floating-promise
eslint-plugin-no-floating-promise - npm
Detects missing await on async function calls. Latest version: 2.0.0, last published: 2 years ago. Start using eslint-plugin-no-floating-promise in your project by running `npm i eslint-plugin-no-floating-promise`. There are 8 other projects ...
» npm install eslint-plugin-no-floating-promise
Published Apr 18, 2024
Version 2.0.0
Author Sebastien Guillemot
CodeSandbox
codesandbox.io › examples › package › eslint-plugin-promise
eslint-plugin-promise examples - CodeSandbox
Use this online eslint-plugin-promise playground to view and fork eslint-plugin-promise example apps and templates on CodeSandbox.
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › docs › rules › always-return.md
eslint-plugin-promise/docs/rules/always-return.md at main · eslint-community/eslint-plugin-promise
You can pass an { ignoreAssignmentVariable: [] } as an option to this rule with a list of variable names so that the last then() callback in a promise chain does not warn if it does an assignment to a global variable. Default is ["globalThis"]. /* eslint promise/always-return: ["error", { ignoreAssignmentVariable: ["globalThis"] }] */ // OK promise.then((x) => { globalThis = x }) promise.then((x) => { globalThis.x = x }) // OK promise.then((x) => { globalThis.x.y = x }) // NG promise.then((x) => { anyOtherVariable = x }) // NG promise.then((x) => { anyOtherVariable.x = x }) // NG promise.then((x) => { x() })
Author eslint-community
Top answer 1 of 3
23
I wonder why no one mentioned the "No floating promises" rule from "typescript-eslint", which forces all promises to be handled appropriately either with async/await or then/catch — https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md
Probably it should be called "No unhandled promises". :)
2 of 3
7
ESLint itself does not have the functionality you are looking for, but there is a highly popular plugin called eslint-plugin-promise.
Specifically, the catch-or-return rule does what you are asking for:
Ensure that each time a then() is applied to a promise, a catch() is applied as well. Exceptions are made if you are returning that promise.
Valid
CopymyPromise.then(doSomething).catch(errors)
myPromise
.then(doSomething)
.then(doSomethingElse)
.catch(errors)
function doSomethingElse() {
return myPromise.then(doSomething)
}
Invalid
CopymyPromise.then(doSomething)
myPromise.then(doSomething, catchErrors) // catch() may be a little better
function doSomethingElse() {
return myPromise.then(doSomething)
}
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › docs › rules › avoid-new.md
eslint-plugin-promise/docs/rules/avoid-new.md at main · eslint-community/eslint-plugin-promise
Creating promises using new Promise can be used to promisify Node-style callbacks.
Author eslint-community
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › docs › rules › prefer-await-to-then.md
eslint-plugin-promise/docs/rules/prefer-await-to-then.md at main · eslint-community/eslint-plugin-promise
Enforce best practices for JavaScript promises. Contribute to eslint-community/eslint-plugin-promise development by creating an account on GitHub.
Author eslint-community
Npm
npm.io › package › eslint-plugin-promise
Eslint-plugin-promise NPM | npm.io
Enforce best practices for JavaScript promises. ... Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-promise globally.
GitHub
github.com › eslint-community › eslint-plugin-promise › blob › main › docs › rules › param-names.md
eslint-plugin-promise/docs/rules/param-names.md at main · eslint-community/eslint-plugin-promise
new Promise(function (reject, resolve) { ... }) // incorrect order new Promise(function (ok, fail) { ... }) // non-standard parameter names new Promise(function (_, reject) { ...
Author eslint-community