No Redundant Alias Variables
Avoid redundant alias variables that immediately reassign existing values without transformation
Source: .agents/rules/no-redundant-alias-variables.mdc
Metadata
- alwaysApply: true
Content
No Redundant Alias Variables
Avoid creating alias variables that simply copy an existing value without adding any transformation or semantic meaning. These extra variables add noise, make code harder to scan, and increase the surface area for bugs when only one of the names is later updated.
Rules
- Do not introduce a new variable when it is just an immediate alias for another variable or prop with the same meaning.
- Only introduce a new variable if it:
- Applies a real transformation (e.g. unit conversion, parsing, formatting), or
- Adds clear semantic meaning that differs from the original name (e.g.
hasInventoryderived frominventoryCount > 0).
- Prefer using the original variable/prop directly when its name is already clear and accurate.
Examples
// ❌ Avoid: pointless aliases that just reassign
const { shippingFee, deliveryInDays, policyContent } = formData;
const shippingFeeCents = shippingFee;
const deliveryDays = deliveryInDays;
// ✅ Prefer: use the original variables directly
const { shippingFee, deliveryInDays, policyContent } = formData;
// ✅ Or: introduce a new variable only when transforming or changing meaning
const shippingFeeCents = shippingFee * 100; // real unit conversion
const deliveryDaysLabel = `${deliveryInDays} days`; // derived display string