Skip to content

Ratchet unicorn/no-unnecessary-global-this to error (off in tests)#292

Merged
twschiller merged 1 commit into
mainfrom
ratchet-unicorn-global-this
Jun 22, 2026
Merged

Ratchet unicorn/no-unnecessary-global-this to error (off in tests)#292
twschiller merged 1 commit into
mainfrom
ratchet-unicorn-global-this

Conversation

@twschiller

@twschiller twschiller commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

From #279. Enforce the rule in production code; disable it in tests (same pattern as no-global-object-property-assignment in #283), since tests legitimately use globalThis.* for mocking.

Production: drop the redundant globalThis. prefix

The #276 autofix already converted 76 property reads; it leaves method calls alone because dropping the object could in theory change this (safe for these standard globals). Converted the production call sites:

  • getComputedStyleplaceholder, cookie-banner-hide, hidden-text-strip, newsletter-modal-hide, svg-sprite-strip, irrelevant-sections-redact
  • addEventListener/removeEventListenerroute-change.ts
  • setInterval/clearIntervaluse-tab-debug-trace, use-tab-pause
  • requestIdleCallbackyielding-text-walk.ts

Tests: rule disabled

Added unicorn/no-unnecessary-global-this: off to the src/**/__tests__/** override. Tests deliberately reach for globalThis.* — overriding globals for mocks (globalThis.MutationObserver = …), dispatching navigation/scroll events, and reading computed style against the jsdom global. So:

  • The test call sites keep globalThis.dispatchEvent(…) / getComputedStyle(…) (no churn).
  • A now-redundant inline disable in hidden-fee-annotate.test.ts is removed.

(src/__test-mocks__/chrome-mv3-extras.ts sits outside the __tests__ glob, so the rule still applies there — it keeps its one justified inline disable.)

Verification

  • bun run check exit 0 (rule errors in prod; 0 violations; no unused-disable warnings)
  • bun run typecheck clean
  • bun run test — 2059/2059 pass

Refs #279

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 22, 2026 1:20pm

Request Review

From #279. Drop the redundant `globalThis.` prefix on the production Web-API
call sites (the #276 autofix did property reads; it leaves method calls alone
since dropping the object could in theory change `this` — safe for these
standard globals):

- placeholder, cookie-banner-hide, hidden-text-strip, newsletter-modal-hide,
  svg-sprite-strip, irrelevant-sections-redact: getComputedStyle
- route-change: add/removeEventListener
- use-tab-debug-trace, use-tab-pause: setInterval/clearInterval
- yielding-text-walk: requestIdleCallback

Disabled in the `src/**/__tests__/**` override: tests deliberately reach for
`globalThis.*` to mock — overriding globals (`globalThis.MutationObserver = …`),
dispatching events, and reading computed style against the jsdom global. So
the test call sites keep `globalThis.` and a now-redundant inline disable in
hidden-fee-annotate.test.ts is dropped.

Rule is error everywhere else (reverts to unicorn/recommended default).

Refs #279

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@twschiller twschiller force-pushed the ratchet-unicorn-global-this branch from a4e47b0 to 54be4f7 Compare June 22, 2026 13:19
@twschiller twschiller changed the title Ratchet unicorn/no-unnecessary-global-this to error Ratchet unicorn/no-unnecessary-global-this to error (off in tests) Jun 22, 2026
@twschiller twschiller merged commit 70c77fb into main Jun 22, 2026
7 checks passed
@twschiller twschiller deleted the ratchet-unicorn-global-this branch June 22, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant