> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-restricted-globals

[Added in v0.7.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.7.0)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-restricted-globals': 'error',
    },
  },
]);
```

## Rule Details

Disallows specified global variable names. This is useful when a project wants to allow globals in general but forbid specific ones — for example, banning the deprecated global `event` in favor of an explicit handler parameter, or banning ambiguous DOM globals like `name` or `length`.

Examples of **incorrect** code for this rule with `["error", "event", "fdescribe"]`:

```javascript
function onClick() {
  console.log(event);
}

fdescribe("foo", function () {});
```

Examples of **correct** code for this rule with `["error", "event"]`:

```javascript
import event from "event-module";

const event2 = 1;
```

A direct restricted name does not need to be declared through [`languageOptions.globals`](https://rslint.rs/config/language-options.md#languageoptionsglobals): an unshadowed `event` reference is still reported, while a local declaration or import is not. With `checkGlobalObject`, the receiver must be an active global for the file. For example, select `globals.browser` from `@rslint/core` to check `window.foo`, or `globals.worker` to check `self.foo`; no host environment is enabled by default.

The rule also accepts an object form so a custom message can be attached to each restricted name:

```json
{ "no-restricted-globals": ["error", { "name": "event", "message": "Use the local event parameter instead." }] }
```

```javascript
function onClick() {
  console.log(event);
}
```

## Options

The rule accepts either an array of names/objects, or a single object with the following properties:

- `globals` — array of restricted names; each entry is either a string or `{ name, message? }`.
- `checkGlobalObject` — when `true`, also flags access through a global object (`window.foo`, `self.foo`, `globalThis.foo`, and any names configured via `globalObjects`). Defaults to `false`.
- `globalObjects` — additional global object names to check when `checkGlobalObject` is enabled. `globalThis`, `self`, and `window` are always included.

Examples of **incorrect** code for this rule with `{ "globals": ["Promise"], "checkGlobalObject": true }`:

```json
{ "no-restricted-globals": ["error", { "globals": ["Promise"], "checkGlobalObject": true }] }
```

```javascript
globalThis.Promise;
self.Promise;
window.Promise;
```

Examples of **incorrect** code for this rule with a custom `globalObjects` entry:

```json
{
  "no-restricted-globals": [
    "error",
    { "globals": ["Promise"], "checkGlobalObject": true, "globalObjects": ["myGlobal"] }
  ]
}
```

```javascript
myGlobal.Promise;
```

## Original Documentation

- [ESLint: no-restricted-globals](https://eslint.org/docs/latest/rules/no-restricted-globals)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-restricted-globals.js)
