question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `prefer-scoped-selector`

See original GitHub issue

Many 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fregantecommented, Jul 30, 2021

require a compliant CSS selector parser

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.

1reaction
sindresorhuscommented, Jul 30, 2021

This is accepted.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found