noRestrictedGlobals
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/style/noRestrictedGlobals¥Diagnostic Category:
lint/style/noRestrictedGlobals -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
¥Same as
no-restricted-globals
-
¥How to configure
{ "linter": { "rules": { "style": { "noRestrictedGlobals": "error" } } }}¥Description
此规则允许你指定不想在应用中使用的全局变量名称。
¥This rule allows you to specify global variable names that you don’t want to use in your application.
此规则始终禁止引用全局标识符 error 和 event。
¥References to the global identifiers error and event are always disallowed by this rule.
如果你想通过启用某个环境来允许使用一组全局变量,但又想禁止使用其中的一些,那么禁止使用特定的全局变量会很有用。
¥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.
{ "linter": { "rules": { "style": { "noRestrictedGlobals": { "options": { "deniedGlobals": { "$": "jQuery is not allowed. Use native DOM manipulation instead.", "MooTools": "Do not use MooTools, use MeowTools instead." } } } } } }}在上面的示例中,如果尝试在不创建局部变量的情况下使用 $ 或 MooTools,规则将发出诊断信息。
¥In the example above, the rule will emit a diagnostics if tried to use $ or MooTools without
creating a local variable.
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号