useErrorMessage
Diagnostic Category: lint/suspicious/useErrorMessage
Since: v1.8.0
Sources:
- Same as: 
unicorn/error-message 
Description
Section titled DescriptionEnforce passing a message value when creating a built-in error.
This rule enforces a message value to be passed in when creating an instance of a built-in Error object,
which leads to more readable and debuggable code.
Examples
Section titled ExamplesInvalid
Section titled Invalidthrow Error();code-block.js:1:12 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Provide an error message for the error.
  
  > 1 │ throw Error();
      │            ^^
    2 │ 
  
  ℹ Providing meaningful error messages leads to more readable and debuggable code.
  
throw Error('');code-block.js:1:12 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Error message should not be an empty string.
  
  > 1 │ throw Error(”);
      │            ^^^^
    2 │ 
  
  ℹ Providing meaningful error messages leads to more readable and debuggable code.
  
throw new TypeError();code-block.js:1:20 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Provide an error message for the error.
  
  > 1 │ throw new TypeError();
      │                    ^^
    2 │ 
  
  ℹ Providing meaningful error messages leads to more readable and debuggable code.
  
const error = new AggregateError(errors);code-block.js:1:33 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Provide an error message for the error.
  
  > 1 │ const error = new AggregateError(errors);
      │                                 ^^^^^^^^
    2 │ 
  
  ℹ Providing meaningful error messages leads to more readable and debuggable code.
  
Valid
Section titled Validthrow Error('Unexpected property.');throw new TypeError('Array expected.');const error = new AggregateError(errors, 'Promises rejected.');How to configure
Section titled How to configure{  "linter": {    "rules": {      "suspicious": {        "useErrorMessage": "error"      }    }  }}