no-with
禁止 with 语句
在 配置文件 中使用来自 @eslint/js 的 recommended 配置可以启用此规则
with 语句可能有问题,因为它将对象的成员添加到当前作用域,使得无法判断块内的变量实际上引用的是什么。
🌐 The with statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to.
规则详情
🌐 Rule Details
此规则不允许使用 with 语句。
🌐 This rule disallows with statements.
如果 ESLint 在严格模式下解析代码,解析器(而不是这个规则)会报告错误。
🌐 If ESLint parses code in strict mode, the parser (instead of this rule) reports the error.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-with: "error"*/
with (point) {
r = Math.sqrt(x * x + y * y); // is r a member of point?
}
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-with: "error"*/
const r = ({x, y}) => Math.sqrt(x * x + y * y);
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
何时不使用
🌐 When Not To Use It
如果你故意使用 with 语句,那么你可以禁用此规则。
🌐 If you intentionally use with statements then you can disable this rule.
版本
此规则是在 ESLint v0.0.2 中引入。