简中文档

no-shadow-restricted-names

NOTE: this rule is part of the 推荐 rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["推荐"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["no-shadow-restricted-names"],
      "exclude": ["no-shadow-restricted-names"]
    }
  }
}

禁止对受限名称的遮蔽。

以下 (a) 是全局对象的属性,或者 (b) 标识符在 JavaScript 中是“受限”名称:

这些名称在 JavaScript 中并不是保留的,这意味着没有任何东西可以阻止人们将其他值赋值给它们(即遮蔽)。换句话说,您可以将 undefined 用作标识符或变量名。(有关更多详细信息,请参见 MDN

function foo() {
  const undefined = "bar";
  console.log(undefined); // 输出: "bar"
}

当然,像这样遮蔽很可能会让其他开发者感到困惑,应该避免这种情况。此 lint 规则会检测并发出警告。

无效:

const undefined = 42;

function NaN() {}

function foo(Infinity) {}

const arguments = () => {};

try {
} catch (eval) {}

有效:

// 如果未赋值,`undefined` 可能被遮蔽
const undefined;

const Object = 42;

function foo(a: number, b: string) {}

try {
} catch (e) {}

你找到了你需要的东西吗?

编辑此页面
隐私政策