Disallow specified global variables
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.
For instance, early Internet Explorer versions exposed the current DOM event as a global variable event
, but using this variable has been considered as a bad practice for a long time. Restricting this will make sure this variable isn’t used in browser code.
This rule allows you to specify global variable names that you don’t want to use in your application.
This rule takes a list of strings, where each string is a global to be restricted:
Alternatively, the rule also accepts objects, where the global name and an optional custom message are specified:
{
"rules": {
"no-restricted-globals": [
"error",
{
"name": "event",
"message": "Use local parameter instead."
},
{
"name": "fdescribe",
"message": "Do not commit fdescribe. Use describe instead."
}
]
}
}
Examples of incorrect code for sample "event", "fdescribe"
global variable names:
Examples of correct code for a sample "event"
global variable name:
Examples of incorrect code for a sample "event"
global variable name, along with a custom error message:
This rule was introduced in ESLint v2.3.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-restricted-globals