說明

New code must not contain duplicated lines. The quality gate blocks PRs with duplication density above 3%.

Duplicated code is a maintenance burden — a bug fix in one copy misses the others.

為什麼重要

  • Bug risk — fix one copy, forget the other
  • Maintenance cost — every change multiplied by N copies
  • Readability — reader must determine if copies are identical or subtly different

Enforcement

Quality Gate: new_duplicated_lines_density < 3%

正例

// Extract common logic into a shared method
public BigDecimal calculateTotal(List<Item> items, Function<Item, BigDecimal> priceFn) {
    return items.stream()
        .map(priceFn)
        .reduce(BigDecimal.ZERO, BigDecimal::add);
}

反例

// ❌ Same logic copy-pasted for different item types
BigDecimal totalA = itemsA.stream().map(Item::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalB = itemsB.stream().map(Item::getDiscountedPrice).reduce(BigDecimal.ZERO, BigDecimal::add);