版本

no-ex-assign

禁止在 catch 子句中重新赋值异常

推荐

配置文件中使用来自 @eslint/jsrecommended 配置启用此规则

如果在 try 语句中的 catch 子句中意外(或有意)地为异常参数分配了另一个值,则从那时起就无法引用该错误。由于没有 arguments 对象来提供对此数据的替代访问,因此参数的赋值是绝对破坏性的。

规则详情

此规则禁止在 catch 子句中重新赋值异常。

此规则的错误代码示例

在 Playground 中打开
/*eslint no-ex-assign: "error"*/

try {
    // code
} catch (e) {
    e = 10;
}

此规则的正确代码示例

在 Playground 中打开
/*eslint no-ex-assign: "error"*/

try {
    // code
} catch (e) {
    const foo = 10;
}

版本

此规则在 ESLint v0.0.9 中引入。

延伸阅读

Avatar image for bocoup.com
The
bocoup.com

资源

更改语言