Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.44 KB

param-names.md

File metadata and controls

44 lines (31 loc) · 1.44 KB

Enforce consistent param names and ordering when creating new promises (promise/param-names)

💼 This rule is enabled in the ✅ recommended config.

Enforce standard parameter names for Promise constructors

Valid

new Promise(function (resolve) { ... })
new Promise(function (resolve, reject) { ... })
new Promise(function (_resolve, _reject) { ... }) // Unused marker for parameters are allowed

Invalid

new Promise(function (reject, resolve) { ... }) // incorrect order
new Promise(function (ok, fail) { ... }) // non-standard parameter names
new Promise(function (_, reject) { ... }) // a simple underscore is not allowed

Ensures that new Promise() is instantiated with the parameter names resolve, reject to avoid confusion with order such as reject, resolve. The Promise constructor uses the RevealingConstructor pattern. Using the same parameter names as the language specification makes code more uniform and easier to understand.

Options

resolvePattern

You can pass a { resolvePattern: "^_?resolve$" } as an option to this rule to the first argument name pattern that the rule allows. Default is "^_?resolve$".

rejectPattern

You can pass a { rejectPattern: "^_?reject$" } as an option to this rule to the second argument name pattern that the rule allows. Default is "^_?reject$".