Skip to content

Latest commit

Β 

History

History
38 lines (26 loc) Β· 884 Bytes

File metadata and controls

38 lines (26 loc) Β· 884 Bytes

throw-new-error

πŸ“ Require new when creating an error.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

While it's possible to create a new error without using the new keyword, it's better to be explicit.

Examples

// ❌
const error = Error('unicorn');

// βœ…
const error = new Error('unicorn');
// ❌
throw TypeError('unicorn');

// βœ…
throw new TypeError('unicorn');
// ❌
throw lib.TypeError('unicorn');

// βœ…
throw new lib.TypeError('unicorn');