unicorn/error-message
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/error-message": "error",
},
},
];Enforce passing a message value when creating a built-in error.
throw new Error();throw new Error('');throw new TypeError();throw new Error('Unexpected property.');throw new TypeError('Array expected.');const error = new AggregateError(errors, 'Promises rejected.');Examples from the ESLint documentation.
unicorn/error-message
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/error-message": "error",
},
},
];unicorn/error-message
unicorn plugin · style
{
"rules": {
"unicorn/error-message": "error"
}
}suspicious/useErrorMessage
suspicious · since 1.8.0
{
"linter": {
"rules": {
"suspicious": {
"useErrorMessage": "error"
}
}
}
}Prefer Number static methods over global functions and optionally static properties over global constants.
Require new when creating an error.
Prefer .includes() over .indexOf(), .lastIndexOf(), and Array#some() when checking for existence or non-existence.
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().