Rule proposal: `prefer-scoped-selector`
See original GitHub issueMany people don’t know the Element.querySelector()
and Element.querySelectorAll()
behaves differently than most common JavaScript DOM libraries, details.
Got the idea here
Fail
const inner = element.querySelectorAll('.outer .inner');
Pass
const inner = document.querySelectorAll('.outer .inner');
const inner = element.querySelectorAll(':scope .outer .inner');
I’m not sure about these, they are never going to get wrong result.
const inner = element.querySelectorAll('.a');
const inner = element.querySelectorAll('.a + .b');
Should we enforce them consistently, or only check descendant combinator and child combinator?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >Rule proposal: no-query-selector-all-zero #1404 - GitHub
Running the recommended ruleset over my code base, I'm finding code like this: containerEle.getElementsByTagName("form") ...
Read more >SEC Proposes Equity Market Overhaul and Best Execution Rule
The SEC is proposing to amend Regulation NMS to (1) amend the tick sizes under Rule 612 to establish a variable minimum pricing...
Read more >sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal : Require comparator function for `Array#sort()`. Unfunded#2014created bybmish ... Rule proposal: Prefer `prefer-scoped-selector`.
Read more >SEC Proposes Amendments to the Shareholder Proposal Rules
The SEC proposed modifying certain bases for excluding shareholder proposals from company proxy statements. If adopted, these amendments are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Probably not, as it just has to trigger if it lacks
\b:scope\b
, which isn’t exactly common. Even if it finds it, it would be a false positive (i.e. no report) so it’s less annoying.This is accepted.