popcodeorg / popcodeorg/popcode

Highlight jQuery selectors that match 0 elements

Abierto
#1,357 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature
Lenguaje dominante
JavaScript
Estrellas
191
Forks
143
Merge medio
4 d 11 h
PR fusionados (30 d)
5

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza revisando el issue relacionado #1355 y comparando los enfoques propuestos de análisis estático y monkey-patching en tiempo de ejecución. El trabajo estará terminado cuando los selectores de jQuery sin coincidencias reciban la advertencia solicitada en el gutter y, si es factible, un subrayado ondulado, sin tratar como selectores las cadenas válidas de creación de elementos, como $("

").

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, jquery
Área
tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.