Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

JavaScript lets you call error constructors without newError('oops') and new Error('oops') both produce an Error instance. Using new is more explicit and consistent with how other objects are constructed, making the intent immediately clear.
Recommendedrecommended · ☑️ unopinionated
Fixable🔧
Suggestions
The rule matches any identifier or member expression whose name follows the pattern /^(?:[A-Z][\da-z]*)*Error$/ — covering built-ins like TypeError, RangeError, and SyntaxError, as well as custom error classes like ValidationError or HttpError.
// Missing new — plain call
const error = Error('unicorn');

// Missing new — thrown built-in error
throw TypeError('unicorn');

// Missing new — namespaced error
throw lib.TypeError('unicorn');

No configuration options

This rule has no configuration options. It automatically fixes violations by inserting the new keyword before the call expression.
If you use the Effect library, Data.TaggedError(...) is intentionally excluded from this rule because it is a factory function rather than a constructor.

Build docs developers (and LLMs) love