close

no-global-object-property-assignment

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-global-object-property-assignment': 'error',
    },
  },
]);

Disallow assigning properties on the global object.

Global object mutation makes state harder to trace and can overwrite existing globals. Prefer module scope, explicit imports/exports, dependency injection, or a local singleton.

// Incorrect
globalThis.foo = value;
window.foo += 1;
self.foo ||= value;

// Correct
export const foo = value;
const singleton = { foo: value };
globalThis.foo;

The rule checks statically named properties on the effective global global, globalThis, self, and window bindings. Shadowed bindings and dynamic computed properties are ignored. Reads and delete expressions are also allowed.

This port follows eslint-plugin-unicorn v75.0.0.