Skip to content
← Back to rules

eslint/no-restricted-globals Restriction

What it does ​

Specify global variable names that should not be used in your application.

Why is this bad? ​

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.

Examples ​

If we have options:

json
"no-restricted-globals": ["error", "event"]

The following patterns are considered problems:

javascript
function onClick() {
  console.log(event); // Unexpected global variable 'event'. Use local parameter instead.
}

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "no-restricted-globals": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-restricted-globals": "error",
  },
});
bash
oxlint --deny no-restricted-globals

Version ​

This rule was added in v0.4.0.

References ​