-
Notifications
You must be signed in to change notification settings - Fork 1
fix(eslint): stop prefer-global-this making the browser framing check unspellable #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eli Bosley (elibosley)
merged 2 commits into
main
from
claude/eslint-browser-global-this-conflict
Aug 3, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { Linter } from "eslint"; | ||
| import globals from "globals"; | ||
| import unicorn from "eslint-plugin-unicorn"; | ||
|
|
||
| import quality from "../src/eslint/quality.js"; | ||
|
|
||
| // Guards that the canonical browser framing check stays spellable. | ||
| // | ||
| // `window.parent === window` is how DOM code asks "am I in an iframe?" before | ||
| // posting to a host. Under the upstream unicorn recommended set every rewrite | ||
| // is rejected by some other shipped rule (see the comment on | ||
| // `unicorn/prefer-global-this` in src/eslint/quality.js), so the check has no | ||
| // valid spelling and consumers reach for a suppression or an `as unknown as | ||
| // Window` bridge. We ship `prefer-global-this` off to keep it writable. | ||
|
|
||
| const linter = new Linter(); | ||
|
|
||
| const configWithRuleOn = { | ||
| languageOptions: { globals: globals.browser }, | ||
| plugins: { unicorn }, | ||
| rules: { | ||
| "unicorn/prefer-global-this": "error", | ||
| "unicorn/no-unnecessary-global-this": "error", | ||
| }, | ||
| }; | ||
|
|
||
| const FRAMING_CHECK = `const isTopLevel = window.parent === window;\n`; | ||
|
|
||
| test("upstream unicorn rejects the window-based framing check", () => { | ||
| const messages = linter.verify(FRAMING_CHECK, configWithRuleOn, "frame.js"); | ||
| const ruleIds = messages.map((message) => message.ruleId); | ||
|
|
||
| assert.ok( | ||
| ruleIds.includes("unicorn/prefer-global-this"), | ||
| `expected prefer-global-this to fire upstream, got: ${ruleIds.join(", ") || "none"}`, | ||
| ); | ||
| }); | ||
|
|
||
| test("shipped quality concern turns prefer-global-this off", () => { | ||
| assert.equal( | ||
| resolve("unicorn/prefer-global-this"), | ||
| "off", | ||
| "unicorn/prefer-global-this must stay off — see the comment in quality.js", | ||
| ); | ||
| }); | ||
|
|
||
| /** Last-wins lookup of a rule across the concern's flat-config entries. */ | ||
| const resolve = (ruleId) => | ||
| quality.findLast((entry) => entry.rules?.[ruleId] !== undefined)?.rules[ | ||
| ruleId | ||
| ]; | ||
|
|
||
| test("the useful half of the pair is kept", () => { | ||
| // `globalThis.parent` must still trim to `parent` for plain member access. | ||
| assert.equal(resolve("unicorn/no-unnecessary-global-this"), "error"); | ||
|
|
||
| // Documents the contradiction this change resolves: `prefer-global-this` | ||
| // demands `globalThis`, while `sonarjs/no-global-this` forbids it. With | ||
| // `prefer-global-this` off, the pair is consistent again. | ||
| assert.equal(resolve("sonarjs/no-global-this"), "error"); | ||
| assert.equal(resolve("unicorn/prefer-global-this"), "off"); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.