src/content/docs/linter/rules/use-throw-new-error.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.8.0` - Diagnostic Category: [`lint/style/useThrowNewError`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/throw-new-error`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/throw-new-error.md){
"linter": {
"rules": {
"style": {
"useThrowNewError": "error"
}
}
}
}
Require new when throwing an error.
While it's possible to instantiate Error without using the new keyword, it's better to be consistent: modern builtins require new to be instantiated.
Rule matches errors when their name ends with the word "Error" and the first character is uppercase.
throw Error();
throw TypeError('biome');
throw lib.TypeError();
throw new Error();
throw new TypeError('biome');
throw new lib.TypeError();