Disable unicorn/prefer-scoped-selector (#279)#297
Merged
Conversation
The rule's `:scope` rewrite is unsound for this codebase's dominant
query-receiver type. It assumes the receiver is an Element, where
`el.querySelectorAll("foo")` and `el.querySelectorAll(":scope foo")`
are equivalent. But the shadow-piercing scanners take `root: ParentNode`
and run against `Document`, `ShadowRoot`, and `DocumentFragment` at
runtime, where `:scope` is NOT equivalent:
- ShadowRoot / DocumentFragment: `:scope` matches nothing, so
`:scope *` / `:scope noscript` silently return empty.
- Document: `:scope *` excludes `<html>`.
Mechanically applying the suggestion would silently disable defenses
inside shadow DOM (noscript-strip, hidden-text-strip,
unicode-invisibles-strip, trust-badge-annotate,
closed-shadow-root-annotate, …). The Element-receiver sites where
`:scope` is safe are all single-compound selectors with no descendant
combinator, so there's no correctness upside there either. The rule
can't narrow to Element receivers or combinator selectors, so it goes
`off` rather than `warn`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Part of the eslint-plugin-unicorn ratchet (#279).
Verdict: turn off, don't ratchet
unicorn/prefer-scoped-selectorflags 64 sites and wantsel.querySelector("foo")→el.querySelector(":scope foo"). That rewriteis only behavior-preserving when the receiver is an Element. This
codebase's shadow-piercing scanners take
root: ParentNodeand run againstDocument,ShadowRoot, andDocumentFragmentreceivers at runtime, where:scopeis not equivalent — verified in jsdom:qsa("*")qsa(":scope *")<html>):scope noscripton a ShadowRoot → 0 (vs 1); comma-lists break partially(
:scope p, span→ 1 vs 2). So mechanically applying the rule's suggestionwould silently disable defenses inside shadow DOM —
noscript-strip,hidden-text-strip,unicode-invisibles-strip,trust-badge-annotate,closed-shadow-root-annotate, and others that scanroot: ParentNode.The Element-receiver sites where
:scopeis safe are all single-compoundselectors (
*,a[href],img, picture) with no descendant combinator, sothere's no correctness upside there either. The rule can't narrow to Element
receivers or to combinator-bearing selectors, so it goes
off(per the"disable no-plan rules, don't leave noisy warnings" convention) rather than
staying
warn.Config-only change; no source edits.
bun run check(0 errors) andtypecheckpass.🤖 Generated with Claude Code