useErrorMessage
诊断类别:lint/suspicious/useErrorMessage
¥Diagnostic Category: lint/suspicious/useErrorMessage
自从:v1.8.0
来源:
¥Since: v1.8.0
Sources:
-
与以下相同:
unicorn/error-message
¥Same as:
unicorn/error-message
强制 onClick 至少伴随以下之一:
¥Enforce passing a message value when creating a built-in error.
此规则强制在创建内置 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
¥Invalid
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.
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.
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.
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
¥Related links