Skip to content
← Back to rules

eslint/no-implicit-globals Restriction

What it does

Disallows declarations in the global scope, global variable leaks, and writes or redeclarations of read-only globals.

Why is this bad?

Browser scripts share a global scope. Top-level var and function declarations, and assignments to undeclared variables in sloppy mode, create globals that can collide with other scripts.

Examples

Examples of incorrect code for this rule:

js
var foo = 1;
function bar() {}
baz = 1;

Examples of correct code for this rule:

js
window.foo = 1;
(function () {
  var bar = 1;
})();

Configuration

lexicalBindings

type: boolean

default: false

How to use

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

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

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

Version

This rule was added in vnext.

References