SubclassingDocumentation 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.
Error has several common pitfalls: forgetting to set this.name, assigning this.message redundantly when the value is already passed to super(), and using this.constructor.name instead of a string literal (which breaks after minification). This rule enforces the one correct pattern for extending any class whose name ends in Error.
| Recommended | — |
| Fixable | 🔧 Auto-fix |
| Suggestions | — |
Examples
Rules enforced
- The class name must be
PascalCaseand end withError(for example,FooError, notfoo). - The constructor must call
super(). - The error message must be passed to
super(), not assigned viathis.message. this.namemust be set to a string literal matching the class name — notthis.constructor.name.
This rule works with any superclass whose name ends in
Error, not just the built-in Error. For example, class MyError extends TypeError is also checked.