1 # Disallow specific global variables (no-restricted-globals)
3 Disallowing usage of specific global variables can be useful if you want to allow a set of global
4 variables by enabling an environment, but still want to disallow some of those.
6 For instance, early Internet Explorer versions exposed the current DOM event as a global variable
7 `event`, but using this variable has been considered as a bad practice for a long time. Restricting
8 this will make sure this variable isn't used in browser code.
12 This rule allows you to specify global variable names that you don't want to use in your application.
16 This rule takes a list of strings, where each string is a global to be restricted:
21 "no-restricted-globals": ["error", "event", "fdescribe"]
26 Alternatively, the rule also accepts objects, where the global name and an optional custom message are specified:
31 "no-restricted-globals": [
35 "message": "Use local parameter instead."
39 "message": "Do not commit fdescribe. Use describe instead."
46 Examples of **incorrect** code for sample `"event", "fdescribe"` global variable names:
49 /*global event, fdescribe*/
50 /*eslint no-restricted-globals: ["error", "event", "fdescribe"]*/
56 fdescribe("foo", function() {
60 Examples of **correct** code for a sample `"event"` global variable name:
64 /*eslint no-restricted-globals: ["error", "event"]*/
66 import event from "event-module";
71 /*eslint no-restricted-globals: ["error", "event"]*/
76 Examples of **incorrect** code for a sample `"event"` global variable name, along with a custom error message:
80 /* eslint no-restricted-globals: ["error", { name: "event", message: "Use local parameter instead." }] */
83 console.log(event); // Unexpected global variable 'event'. Use local parameter instead.
89 * [no-restricted-properties](no-restricted-properties.md)
90 * [no-restricted-syntax](no-restricted-syntax.md)