Guide section 5.1 on object destructuring may lead to anti-pattern
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
- Área
- documentation
Línea de trabajo
Comienza con la sección 5.1, «Use object destructuring when accessing and using multiple properties of an object», en README.md y compara sus indicaciones con los ejemplos de este issue. Revisa los casos de anti-patrones propuestos y añade indicaciones que expliquen cuándo puede ser preferible el acceso directo a las propiedades, con un ejemplo claro de la regla prevista.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This issue is realted to guide section 5.1 Use object destructuring when accessing and using multiple properties of an object
Although the section rationale and examples are very clear and logical, IMO when followed unrestrictedly (or naively) it may lead to an anti-pattern with the bad features this very section is trying to avoid in the first place (repetitive code, opportunities for mistakes and unnecessary extra temporary references).
Apparently the anti-pattern arises more clearly when there is a combination of these conditions:
- Accessed object properties have meaningful names and are each only referenced once, thus not requiring local variables.
- There are more than a handful of accessed properties
- The accessed properties are mostly used to create a new object, with or without key/value transformations
Here's an example to illustrate:
// bad
function toNewUserType(user) {
const {
id: userId,
status: userStatus,
email,
phone,
encryptedPassword,
firstName,
middleName,
lastName,
jobTitle,
birthDate,
createdAt,
updatedAt,
address,
} = user;
return {
userId,
userStatus,
email,
phone,
encryptedPassword,
jobTitle,
birthDate,
createdAt: toDate(createdAt),
updatedAt: toDate(updatedAt),
address: toNewAddressType(address),
userHash: idToHash(userId),
fullName: getFullName(firstName, middleName, lastName),
};
}
// still bad
function toNewUserType({
id: userId,
status: userStatus,
email,
phone,
encryptedPassword,
firstName,
middleName,
lastName,
jobTitle,
birthDate,
createdAt,
updatedAt,
address,
}) {
return {
userId,
userStatus,
email,
phone,
encryptedPassword,
jobTitle,
birthDate,
createdAt: toDate(createdAt),
updatedAt: toDate(updatedAt),
address: toNewAddressType(address),
userHash: idToHash(userId),
fullName: getFullName(firstName, middleName, lastName),
};
}
// good
function toNewUserType(user) {
return {
userId: user.id,
userStatus: user.status,
email: user.email,
phone: user.phone,
encryptedPassword: user.encryptedPassword,
jobTitle: user.jobTitle,
birthDate: user.birthDate,
createdAt: toDate(user.createdAt),
updatedAt: toDate(user.updatedAt),
address: toNewAddressType(user.address),
userHash: idToHash(user.id),
fullName: getFullName(user.firstName, user.middleName, user.lastName),
};
}
If the package owners agree with the problem, I believe we should be able to add some content to warn about this anti-pattern and how to avoid it.
Thanks in advance.
- Lenguaje dominante
- JavaScript
- Estrellas
- 148k
- Forks
- 26.6k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de airbnb/javascript
-
Severity: Unhandled promise rejection in `whitespace-async.js` when ESLint async path is usedPosiblemente ocupada @bodapatisaikrishna la tomó hace 23 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
airbnb/javascript#3237 · 6 comentarios ·
-
Inconsistent semicolon usage in examples (Arrays vs Functions)Posiblemente ocupada @Developer-shivamMishra la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
airbnb/javascript#3152 · 4 comentarios ·
-
No error handling around execSync + JSON.parse in whitespace.js (ESLint 9 path)Posiblemente ocupada @dataCenter430 la tomó hace 219 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
airbnb/javascript#3238 · 8 comentarios ·
-
Upgrading eslint-plugin-react-hooksPosiblemente ocupada @weihongyu12 la tomó hace 364 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 38/100
airbnb/javascript#3186 · 3 comentarios · 2 reacciones ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
airbnb/javascript#3173 · 9 comentarios · 1 reacción ·
Todos los issues de airbnb/javascript
Issues similares
-
Tool errors containing cycles or BigInt crash getErrorMessage and replace the original failureAbiertofactory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
vercel/ai#22796 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
fix(knowledge): list-promotion-candidates prints a stack trace on a malformed claim inventoryAbiertogood first issue needs-triage priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
melodic-software/claude-code-plugins#6982 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
chore v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/servers#5115 ·
Los mantenedores suelen responder en 1 día
-
beginner bug good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
philaconvalley/website#168 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día