unicorn/throw-new-error
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/throw-new-error": "error",
},
},
];const error = Error('unicorn');throw TypeError('unicorn');throw lib.TypeError('unicorn');const error = new Error('unicorn');throw new TypeError('unicorn');throw new lib.TypeError('unicorn');Examples from the ESLint documentation.
unicorn/throw-new-error
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/throw-new-error": "error",
},
},
];unicorn/throw-new-error
unicorn plugin · style
{
"rules": {
"unicorn/throw-new-error": "error"
}
}style/useThrowNewError
style · since 1.8.0
{
"linter": {
"rules": {
"style": {
"useThrowNewError": "error"
}
}
}
}Prefer Number static methods over global functions and optionally static properties over global constants.
Prefer .includes() over .indexOf(), .lastIndexOf(), and Array#some() when checking for existence or non-existence.
Enforce passing a message value when creating a built-in error.
Require escape sequences to use uppercase or lowercase values.
Disallow instanceof with built-in objects
Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer().