|
| 1 | +# structure.duplicate-function-signatures |
| 2 | + |
| 3 | +Flags repeated non-test helper shapes that show up across several source files. |
| 4 | + |
| 5 | +- **Family:** `structure` |
| 6 | +- **Severity:** `medium` |
| 7 | +- **Scope:** `file` |
| 8 | +- **Requires:** `repo.duplicateFunctionSignatures` |
| 9 | + |
| 10 | +## How it works |
| 11 | + |
| 12 | +A repo-level fact builds structural fingerprints for function bodies, normalizing local names so copy-pasted helpers still match after superficial renaming. |
| 13 | +The rule then projects those duplicate clusters back onto each affected file. |
| 14 | + |
| 15 | +A cluster only counts when it appears in **3 or more files**. |
| 16 | +Tiny functions and pass-through wrappers are excluded before clustering, and test files are skipped entirely. |
| 17 | + |
| 18 | +## Flagged example |
| 19 | + |
| 20 | +```ts |
| 21 | +// src/users/normalize.ts |
| 22 | +export function normalizeUser(input: ApiUser) { |
| 23 | + const name = input.name?.trim() ?? ""; |
| 24 | + const email = input.email?.toLowerCase() ?? ""; |
| 25 | + return { name, email, active: Boolean(input.active) }; |
| 26 | +} |
| 27 | + |
| 28 | +// src/teams/normalize.ts |
| 29 | +export function normalizeTeamMember(member: ApiMember) { |
| 30 | + const name = member.name?.trim() ?? ""; |
| 31 | + const email = member.email?.toLowerCase() ?? ""; |
| 32 | + return { name, email, active: Boolean(member.active) }; |
| 33 | +} |
| 34 | + |
| 35 | +// src/accounts/normalize.ts |
| 36 | +export function normalizeAccountOwner(owner: ApiOwner) { |
| 37 | + const name = owner.name?.trim() ?? ""; |
| 38 | + const email = owner.email?.toLowerCase() ?? ""; |
| 39 | + return { name, email, active: Boolean(owner.active) }; |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +## Usually ignored |
| 44 | + |
| 45 | +```ts |
| 46 | +export function getUser(id: string) { |
| 47 | + return loadUser(id); |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +Pass-through wrappers are excluded, and a duplicate that only appears in 2 files is below the reporting threshold. |
| 52 | + |
| 53 | +## Scoring |
| 54 | + |
| 55 | +Each duplicate cluster adds `1.25 + 0.5 * (fileCount - 3)` for the current file, capped at `6`. |
0 commit comments