Ratchet unicorn/no-unnecessary-global-this to error (off in tests)#292
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
a4e47b0 to
54be4f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From #279. Enforce the rule in production code; disable it in tests (same pattern as
no-global-object-property-assignmentin #283), since tests legitimately useglobalThis.*for mocking.Production: drop the redundant
globalThis.prefixThe #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:getComputedStyle—placeholder,cookie-banner-hide,hidden-text-strip,newsletter-modal-hide,svg-sprite-strip,irrelevant-sections-redactaddEventListener/removeEventListener—route-change.tssetInterval/clearInterval—use-tab-debug-trace,use-tab-pauserequestIdleCallback—yielding-text-walk.tsTests: rule disabled
Added
unicorn/no-unnecessary-global-this: offto thesrc/**/__tests__/**override. Tests deliberately reach forglobalThis.*— overriding globals for mocks (globalThis.MutationObserver = …), dispatching navigation/scroll events, and reading computed style against the jsdom global. So:globalThis.dispatchEvent(…)/getComputedStyle(…)(no churn).hidden-fee-annotate.test.tsis removed.(
src/__test-mocks__/chrome-mv3-extras.tssits outside the__tests__glob, so the rule still applies there — it keeps its one justified inline disable.)Verification
bun run checkexit 0 (rule errors in prod; 0 violations; no unused-disable warnings)bun run typecheckcleanbun run test— 2059/2059 passRefs #279