• Stars
    star
    707
  • Rank 64,036 (Top 2 %)
  • Language
    JavaScript
  • Created almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enforce best practices for JavaScript promises

eslint-plugin-promise

Enforce best practices for JavaScript promises.

CI npm version code style: prettier

Installation

You'll first need to install ESLint:

npm install eslint --save-dev

Next, install eslint-plugin-promise:

npm install eslint-plugin-promise --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-promise globally.

Usage

Add promise to the plugins section of your .eslintrc.json configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["promise"]
}

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"
  }
}

or start with the recommended rule set:

{
  "extends": ["plugin:promise/recommended"]
}

Rules

💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🚫 Configurations disabled in.
Set in the recommended configuration.
🔧 Automatically fixable by the --fix CLI option.

Name                      Description 💼 ⚠️ 🚫 🔧
always-return Require returning inside each then() to create readable and reusable Promise chains.
avoid-new Disallow creating new promises outside of utility libs (use pify instead).
catch-or-return Enforce the use of catch() on un-returned promises.
no-callback-in-promise Disallow calling cb() inside of a then() (use nodeify instead).
no-multiple-resolved Disallow creating new promises with paths that resolve multiple times.
no-native Require creating a Promise constructor before using it in an ES5 environment.
no-nesting Disallow nested then() or catch() statements.
no-new-statics Disallow calling new on a Promise static method. 🔧
no-promise-in-callback Disallow using promises inside of callbacks.
no-return-in-finally Disallow return statements in finally().
no-return-wrap Disallow wrapping values in Promise.resolve or Promise.reject when not needed.
param-names Enforce consistent param names and ordering when creating new promises.
prefer-await-to-callbacks Prefer async/await to the callback pattern.
prefer-await-to-then Prefer await to then()/catch()/finally() for reading Promise values.
valid-params Enforces the proper number of arguments are passed to Promise functions.

Maintainers

License

More Repositories

1

redux-shopping-cart

A basic redux shopping cart example
TypeScript
93
star
2

exchange-rate

Sample code for learning redux with hooks by creating an exchange rate calculator
JavaScript
51
star
3

CollabPaintJS

A collaborative painting app built on top of NodeJS and Socket.IO
JavaScript
45
star
4

egghead-rtkq

A repo to showcase using rtk query
JavaScript
18
star
5

egghead-express

Resources for my Egghead collection on using express 5
JavaScript
12
star
6

grunt-lintblame

Combines git blame with the linter tool to see who caused each error.
JavaScript
7
star
7

asts-utahjs-2015

Notes and demo from my AST talk at UtahJS 2015
JavaScript
7
star
8

HTML5-Meter-Shim

Provides Backward Compatible Support for the meter tag
5
star
9

html5-dialog-shim

Add HTML5 dialog support to HTML5 browsers.
JavaScript
5
star
10

SVG-is-Rad

JavaScript
3
star
11

fillerup

Dynamic CSS Injection for base64d SVGs
JavaScript
3
star
12

eslint-plugin-modules

ESLint rules for JavaScript modules.
JavaScript
3
star
13

eslint-demo

A simple demo of custom rules in ESLint
JavaScript
3
star
14

words-vs-zombies

Word Game + Zombies
JavaScript
3
star
15

HTML5-Fish

An HTML5 game experiment. There are many branches with different versions. Check them all out!
JavaScript
2
star
16

slide-web

Generic Backbone/AMD/Handlebars example
JavaScript
2
star
17

gitblame

Use git blame to find out who modified a file.
JavaScript
2
star
18

jQuery-Canvas-Loader

HTML5 canvas-based loading icons created using jQuery
2
star
19

about

2
star
20

error-handling

Error Handling Demos
JavaScript
1
star
21

webpack2-example

Messing around with webpack 2
JavaScript
1
star
22

DirtSweeper

Android Game
PHP
1
star
23

es6-test

A sample ES6 Node.js app using Express 4
JavaScript
1
star
24

xjamundx.github.com

1
star
25

breakout

Basic block smashing game
JavaScript
1
star
26

Skate

HTML5 Skate Game
JavaScript
1
star
27

dead-code

Quick Webpack / Uglify Dead Code Test
JavaScript
1
star
28

tetris

A basic falling blocks game implemented in JavaScript
JavaScript
1
star
29

joy-of-react-wordle

JavaScript
1
star
30

CanvasLoader

Creates an HTML5 Canvas-based loading icon with Javascript
1
star