popcodeorg / popcodeorg/popcode

Highlight jQuery selectors that match 0 elements

Aperta
#1,357 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature
Lingua principale
JavaScript
Stelle
191
Fork
143
Merge medio
4g 11h
PR unite (30g)
5

Descrizione

Related to #1355 , but probably harder.

If the user's JS code calls jQuery with a selector that doesn't match any elements on the page, there's probably a mistake in their code. Whatever they do with that jQuery collection afterwards (trying to change something or attaching a click handler) will have no effect, but jQuery won't error on it because it's perfectly valid to attach a click handler to a collection with zero elements. These kinds of bugs are hard to find, and they're frequent, because students often typo IDs or forget to prefix with a #.

We should highlight these selectors the same way as #1355 (a warning symbol in the gutter and, if feasible, a squiggly yellow/orange underline).

Capturing these might be tricky. One approach could be to use static code analysis to find code that looks like $("some string") and check whether the string is a syntactically valid selector that matches zero elements. We'd have to be careful here, because $("<div>") is not a valid CSS selector but is a valid thing to pass to jQuery. Another approach could be to detect these at run-time by monkey-patching jQuery (i.e. make the $ function a wrapper around the actual jQuery function that first checks if the input is a zero-match selector), but that could cause us to miss broken selectors in code that isn't immediately executed.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando l’issue correlata #1355 e confrontando gli approcci proposti di analisi statica e monkey-patching a runtime. Il lavoro è completato quando i selettori jQuery senza corrispondenze ricevono l’avviso richiesto nel gutter e, se fattibile, una sottolineatura ondulata, senza trattare come selettori le stringhe valide per la creazione di elementi come $("

").

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, jquery
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.