Skip to content

noRestrictedGlobals

诊断类别:lint/style/noRestrictedGlobals

¥Diagnostic Category: lint/style/noRestrictedGlobals

自从:v1.0.0 来源:

¥Since: v1.0.0 Sources:

此规则允许你指定不想在应用中使用的全局变量名称。

¥This rule allows you to specify global variable names that you don’t want to use in your application.

如果你想通过启用环境来允许一组全局变量,但仍想禁止其中一些全局变量,则禁止使用特定的全局变量会很有用。

¥Disallowing usage of specific global variables can be useful if you want to allow a set of global variables by enabling an environment, but still want to disallow some of those.

¥Examples

¥Invalid

console.log(event)
code-block.js:1:13 lint/style/noRestrictedGlobals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not use the global variable event.

> 1 │ console.log(event)
^^^^^
2 │

Use a local variable instead.

¥Valid

function f(event) {
console.log(event)
}

¥Options

使用选项指定要在源代码中限制的其他全局变量。

¥Use the options to specify additional globals that you want to restrict in your source code.

{
"//": "...",
"options": {
"deniedGlobals": ["$", "MooTools"]
}
}

在上面的示例中,如果尝试在不创建局部变量的情况下使用 $MooTools,规则将发出诊断信息。

¥In the example above, the rule will emit a diagnostics if tried to use $ or MooTools without creating a local variable.

¥Related links