Duplicated logic is a maintenance trap: every bug fix, every business rule change, and every refactor must happen in N places simultaneously. Miss one copy and you ship an inconsistency. ISO 25010 maintainability.reusability directly penalizes this pattern. AI-generated codebases accumulate duplicate logic across sessions because the model rewrites familiar patterns rather than importing the utility it generated three sessions ago. Date formatting, currency conversion, and API error handling are the most common duplicated patterns.
Medium because duplicated logic creates divergence risk on every future change, but individual copies typically function correctly in isolation until they get out of sync.
Extract duplicated utility logic into a shared module and replace each copy with the import:
// lib/utils/format.ts
export function formatCurrency(amount: number, currency = 'USD'): string {
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount)
}
export function formatRelativeDate(date: Date): string {
// single implementation, used everywhere
}
Your IDE's "Extract to function" refactor handles the initial extraction. After centralizing, run a search for the old inline pattern to confirm all copies are replaced.
ID: code-maintainability.code-organization.shared-logic-extracted
Severity: medium
What to look for: Look for duplicated logic across component files. Common patterns to find:
Search for identical or near-identical function bodies appearing in more than two files. Also check whether a lib/, utils/, or helpers/ directory exists and is actually used by components — or if it's empty/missing while components contain helper logic.
Pass criteria: Count all instances of duplicated non-trivial logic (over 5 lines) across the codebase. Common utility logic is centralized in shared modules (lib/, utils/, helpers/). No more than 2 instances of duplicated non-trivial logic found across all files. Report the count: "Found X instances of duplicated logic across Y files."
Fail criteria: Three or more instances of duplicated non-trivial logic found, OR components contain substantial utility functions that are never shared despite being used in multiple places.
Skip (N/A) when: The project has fewer than 5 source files — not enough surface area to evaluate. Signal: fewer than 5 distinct source files outside of config.
Detail on fail: Name the duplicated pattern. Example: "Date formatting logic duplicated in components/EventCard.tsx, components/ProfileHeader.tsx, and app/dashboard/page.tsx — none share a utility function." or "API error handling pattern copy-pasted across 4 route handlers."
Remediation: Duplicated logic is a maintenance debt: every bug fix and every change has to happen in N places. Extract shared logic into a utility module and import it:
// lib/utils/format.ts
export function formatCurrency(amount: number, currency = 'USD'): string {
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount)
}
export function formatRelativeDate(date: Date): string {
// single implementation, used everywhere
}
Then replace each duplicate with the import. Your IDE's "Extract to function" refactor can automate the initial extraction.