Reviewer · Code Style
Eliminate redundant code
Favor the simplest, most self-contained way to express logic, and remove redundancy such as unnecessary helper functions, duplicate parameters, or multi-step object mutation when a direct expression or existing reference already achieves the goal. Before adding a helper, extra parameter, or intermediate variable, check whether the surrounding code already...
Favor the simplest, most self-contained way to express logic, and remove redundancy such as unnecessary helper functions, duplicate parameters, or multi-step object mutation when a direct expression or existing reference already achieves the goal. Before adding a helper, extra parameter, or intermediate variable, check whether the surrounding code already exposes the needed data or whether a simpler expression can replace it.
For example, instead of introducing a dedicated helper to pick a property key:
// Avoid
key: isHyphenatedJsxProp(prop.originalName)
? {kind: 'string', name: prop.originalName}
: {kind: 'string', name: prop.newName},
// Prefer
key: {
kind: 'string',
name: prop.originalName !== prop.newName ? prop.originalName : prop.newName,
},
Similarly, avoid passing values that are already reachable through an existing reference:
// Avoid
validateExhaustiveDependencies(hir, env).unwrap();
// Prefer (hir already exposes its environment)
validateExhaustiveDependencies(hir).unwrap();
And prefer self-contained accessor patterns (e.g., getters) over assigning placeholder objects and mutating them later with Object.assign, keeping configuration or exported objects easy to read in one place. This keeps code concise, reduces the surface area for bugs, and makes intent clearer to future readers.