Skip to content

noCatchAssign

¥Summary

  • 规则生效日期:v1.0.0

    ¥Rule available since: v1.0.0

  • 诊断类别:lint/suspicious/noCatchAssign

    ¥Diagnostic Category: lint/suspicious/noCatchAssign

  • 此规则为推荐规则,默认启用。

    ¥This rule is recommended, which means is enabled by default.

  • 此规则没有修复方案。

    ¥This rule doesn’t have a fix.

  • 此规则的默认严重级别为 warning

    ¥The default severity of this rule is warning.

  • 来源:

    ¥Sources:

¥How to configure

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noCatchAssign": "error"
}
}
}
}

¥Description

禁止在 catch 子句中重新分配异常。

¥Disallow reassigning exceptions in catch clauses.

分配给 catch 参数可能会产生误导和混淆。这通常是无意的,并且表明程序员犯了错误。

¥Assignment to a catch parameter can be misleading and confusing. It is often unintended and indicative of a programmer error.

¥Examples

¥Invalid

try {
} catch (e) {
e;
e = 10;
}
code-block.js:5:3 lint/suspicious/noCatchAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Reassigning a catch parameter is confusing.

3 │ } catch (e) {
4 │ e;
> 5 │ e = 10;
^
6 │ }
7 │

The catch parameter is declared here:

1 │ try {
2 │
> 3 │ } catch (e) {
^
4 │ e;
5 │ e = 10;

Use a local variable instead.

¥Valid

try {
} catch (e) {
let e = 10;
e = 100;
}

¥Related links