nodejs / nodejs/node

Replacement/improvement of `func-name-matching` eslint rule

Abierto
#57,899 3 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stale tools
Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.4k
Merge medio
4 d 3 h
PR fusionados (30 d)
272

Descripción

There are quite a few places where a property is defined like this:

ObjectDefineProperty(someObject, 'someFunction', {
  __proto__: null,
  value: function() {
    /* `someObject.someFunction`'s body */
  },
});

As result, we end up with quite a few functions named value:

someObject.someFunction.name === 'value'

There is a func-name-matching rule in eslint that enforces function names to match the property names. However, in these cases, this rule rejects correct code and insists that these functions must be named value, to the point that in some places we have them explicitly named like this: https://github.com/nodejs/node/blob/cb5f671a34da32e3c2d70d7f3e7f869cda6b806b/lib/test/reporters.js#L56

I think, it would be nice to have a custom linter rule that:

  • works the same way as func-name-matching everywhere outside of ObjectDefineProperty, ObjectDefineProperties, and ReflectDefineProperty
  • in the descriptors in these functions, the rule should be reversed: it should not allow the function to end up with a name value
  • (ideally) if property name(s) is defined as plain string, the function name must match this string

I'm not familiar with eslint rules definitions but the original func-name-matching rule seems to be defined here: https://github.com/eslint/eslint/blob/e8f8d57bd6c0d95f9f25db8c5b3ff72de42488b7/lib/rules/func-name-matching.js.

The rule already has considerPropertyDescriptor option, but it's not applicable here because:

  • it recognizes the normal form of these functions (Object.defineProperty) but not primordials (ObjectDefineProperty)
  • it still allows both implicitly inherited name (value: function() {) and concise notation (value() {)
  • it also disables the rule inside of Object.create()

Guía de contribución

Abrir la guía de contribución

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

Empieza leyendo la regla vinculada func-name-matching de ESLint y el ejemplo vinculado reporters.js de Node.js; después compara cómo se representan los descriptores de ObjectDefineProperty, ObjectDefineProperties y ReflectDefineProperty. Se considera terminado cuando una regla personalizada conserva el matching normal en el resto de los casos, rechaza las funciones descriptor que se convierten en named value y gestiona los nombres de propiedad que son cadenas simples según lo especificado.

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

Evaluación

Stack tecnológico
eslint, javascript
Área
tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.