Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 1.03 KB

no-callback-literal.md

File metadata and controls

35 lines (23 loc) · 1.03 KB

Enforce Node.js-style error-first callback pattern is followed (n/no-callback-literal)

When invoking a callback function which uses the Node.js error-first callback pattern, all of your errors should either use the Error class or a subclass of it. It is also acceptable to use undefined or null if there is no error.

📖 Rule Details

When a function is named cb or callback, then it must be invoked with a first argument that is undefined, null, an Error class, or a subclass of Error.

Examples of 👎 incorrect code for this rule:

/*eslint n/no-callback-literal: "error" */

cb('this is an error string');
cb({ a: 1 });
callback(0);

Examples of 👍 correct code for this rule:

/*eslint n/no-callback-literal: "error" */

cb(undefined);
cb(null, 5);
callback(new Error('some error'));
callback(someVariable);

🔎 Implementation