@aiready/pattern-detect 0.17.8 → 0.17.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/analyzer-entry/index.d.mts +1 -1
  2. package/dist/analyzer-entry/index.d.ts +1 -1
  3. package/dist/analyzer-entry/index.js +370 -135
  4. package/dist/analyzer-entry/index.mjs +4 -3
  5. package/dist/chunk-2P7BQHGR.mjs +306 -0
  6. package/dist/{chunk-VGMM3L3O.mjs → chunk-3EORD7DC.mjs} +1 -1
  7. package/dist/{chunk-GREN7X5H.mjs → chunk-4PVPQMRT.mjs} +2 -2
  8. package/dist/{chunk-RS73WLNI.mjs → chunk-6VDL7TAS.mjs} +5 -113
  9. package/dist/chunk-AQIP4JGM.mjs +283 -0
  10. package/dist/{chunk-JBUZ6YHE.mjs → chunk-B4NLWKPZ.mjs} +85 -9
  11. package/dist/chunk-IPBGVPUX.mjs +143 -0
  12. package/dist/chunk-LUUJOUK5.mjs +283 -0
  13. package/dist/chunk-P3BOCGVV.mjs +498 -0
  14. package/dist/{scoring-entry.js → chunk-PHJE6A3J.mjs} +20 -37
  15. package/dist/chunk-PQXOORR4.mjs +234 -0
  16. package/dist/{chunk-GLKAGFKX.mjs → chunk-RDR75DVI.mjs} +85 -9
  17. package/dist/chunk-SXVLRPMF.mjs +143 -0
  18. package/dist/{chunk-DNZS4ESD.mjs → chunk-SY7RX5YQ.mjs} +85 -9
  19. package/dist/{context-rules-entry.js → chunk-TIBF7KST.mjs} +81 -78
  20. package/dist/chunk-WYYSQX5M.mjs +467 -0
  21. package/dist/{chunk-I6ETJC7L.mjs → chunk-X553BOMI.mjs} +56 -26
  22. package/dist/{chunk-K7BO57OO.mjs → chunk-Y6OB7K34.mjs} +80 -4
  23. package/dist/chunk-YLVV6YZ5.mjs +143 -0
  24. package/dist/chunk-ZUWPFVJV.mjs +115 -0
  25. package/dist/chunk-ZZMONVPE.mjs +467 -0
  26. package/dist/cli.js +402 -167
  27. package/dist/cli.mjs +4 -3
  28. package/dist/context-rules-entry/index.d.mts +35 -1
  29. package/dist/context-rules-entry/index.d.ts +35 -1
  30. package/dist/context-rules-entry/index.js +194 -48
  31. package/dist/context-rules-entry/index.mjs +1 -1
  32. package/dist/detector-entry/index.js +192 -46
  33. package/dist/detector-entry/index.mjs +2 -2
  34. package/dist/{analyzer-entry-BVz-HnZd.d.mts → index-B-pnXpgn.d.mts} +10 -1
  35. package/dist/{index-BwuoiCNm.d.ts → index-CWgYOKaK.d.ts} +35 -16
  36. package/dist/{index-BVz-HnZd.d.mts → index-Dl4BrGIT.d.mts} +35 -16
  37. package/dist/{analyzer-entry-BwuoiCNm.d.ts → index-DqS2e0kK.d.ts} +10 -1
  38. package/dist/index.d.mts +5 -6
  39. package/dist/index.d.ts +5 -6
  40. package/dist/index.js +467 -214
  41. package/dist/index.mjs +37 -22
  42. package/dist/scoring-entry/index.js +7 -3
  43. package/dist/scoring-entry/index.mjs +1 -1
  44. package/package.json +2 -2
  45. package/dist/analyzer-entry.d.mts +0 -100
  46. package/dist/analyzer-entry.d.ts +0 -100
  47. package/dist/analyzer-entry.js +0 -693
  48. package/dist/analyzer-entry.mjs +0 -12
  49. package/dist/chunk-262N2JB7.mjs +0 -497
  50. package/dist/chunk-2R7HOR5H.mjs +0 -777
  51. package/dist/chunk-3D7RVGHM.mjs +0 -64
  52. package/dist/chunk-3LS3E6MO.mjs +0 -508
  53. package/dist/chunk-3VRQYFW3.mjs +0 -782
  54. package/dist/chunk-3WK24ZOX.mjs +0 -860
  55. package/dist/chunk-3YYN6ZXN.mjs +0 -1038
  56. package/dist/chunk-4BPRGZRG.mjs +0 -1041
  57. package/dist/chunk-4UHDGB7U.mjs +0 -920
  58. package/dist/chunk-5LYDB7DY.mjs +0 -771
  59. package/dist/chunk-65G3HXLQ.mjs +0 -497
  60. package/dist/chunk-65UQ5J2J.mjs +0 -64
  61. package/dist/chunk-6JTVOBJX.mjs +0 -64
  62. package/dist/chunk-6OEHUI5J.mjs +0 -1045
  63. package/dist/chunk-6YUGU4P4.mjs +0 -914
  64. package/dist/chunk-7EJGNGXM.mjs +0 -771
  65. package/dist/chunk-7O2DUBSN.mjs +0 -1058
  66. package/dist/chunk-7S4AUL5S.mjs +0 -911
  67. package/dist/chunk-A76JUWER.mjs +0 -786
  68. package/dist/chunk-AJZUNNFH.mjs +0 -817
  69. package/dist/chunk-AXHGYYYZ.mjs +0 -404
  70. package/dist/chunk-BKRPSTT2.mjs +0 -64
  71. package/dist/chunk-BUBQ3W6W.mjs +0 -980
  72. package/dist/chunk-CCHM2VLK.mjs +0 -1051
  73. package/dist/chunk-CHFK6EBT.mjs +0 -419
  74. package/dist/chunk-CMT3MWWO.mjs +0 -948
  75. package/dist/chunk-CMWW24HW.mjs +0 -259
  76. package/dist/chunk-CTDBJP25.mjs +0 -1043
  77. package/dist/chunk-DGAKXYIP.mjs +0 -1041
  78. package/dist/chunk-DQSLTL7J.mjs +0 -788
  79. package/dist/chunk-DR5W7S3Z.mjs +0 -968
  80. package/dist/chunk-EFUKPMBE.mjs +0 -950
  81. package/dist/chunk-EVBFDILL.mjs +0 -927
  82. package/dist/chunk-EXORBAXR.mjs +0 -887
  83. package/dist/chunk-EZT3NZGB.mjs +0 -1057
  84. package/dist/chunk-FWUKMJEQ.mjs +0 -1133
  85. package/dist/chunk-GSJFORRO.mjs +0 -504
  86. package/dist/chunk-H4ADJYOG.mjs +0 -925
  87. package/dist/chunk-H5FB2USZ.mjs +0 -762
  88. package/dist/chunk-H73HEG7M.mjs +0 -670
  89. package/dist/chunk-HOS5Z2NC.mjs +0 -669
  90. package/dist/chunk-HXHQOQB5.mjs +0 -508
  91. package/dist/chunk-INEOYHUM.mjs +0 -911
  92. package/dist/chunk-INJ4SBTV.mjs +0 -754
  93. package/dist/chunk-J5CW6NYY.mjs +0 -64
  94. package/dist/chunk-JAFZCZAP.mjs +0 -776
  95. package/dist/chunk-JKVKOXYR.mjs +0 -407
  96. package/dist/chunk-JTHW7EYW.mjs +0 -1041
  97. package/dist/chunk-JWR3AHKO.mjs +0 -788
  98. package/dist/chunk-KC2CQMG2.mjs +0 -858
  99. package/dist/chunk-KDWGWBP5.mjs +0 -832
  100. package/dist/chunk-KPEK5REL.mjs +0 -919
  101. package/dist/chunk-KT6O2IAE.mjs +0 -861
  102. package/dist/chunk-KWMNN3TG.mjs +0 -391
  103. package/dist/chunk-LUA5FXSZ.mjs +0 -771
  104. package/dist/chunk-LYKRYBSM.mjs +0 -64
  105. package/dist/chunk-M4PQMW34.mjs +0 -480
  106. package/dist/chunk-MH6LBXZF.mjs +0 -816
  107. package/dist/chunk-MHU3CL4R.mjs +0 -64
  108. package/dist/chunk-MJWBS6SM.mjs +0 -1058
  109. package/dist/chunk-OFGMDX66.mjs +0 -402
  110. package/dist/chunk-P7B6Z4I2.mjs +0 -1043
  111. package/dist/chunk-PBCXSG7E.mjs +0 -658
  112. package/dist/chunk-PEEHSFDR.mjs +0 -1058
  113. package/dist/chunk-PSVG2NLH.mjs +0 -966
  114. package/dist/chunk-PWNQ6JZW.mjs +0 -508
  115. package/dist/chunk-QE4E3F7C.mjs +0 -410
  116. package/dist/chunk-QEP76HGK.mjs +0 -1039
  117. package/dist/chunk-QX2BQJEO.mjs +0 -1058
  118. package/dist/chunk-R2S73CVG.mjs +0 -503
  119. package/dist/chunk-RMGDSNLE.mjs +0 -770
  120. package/dist/chunk-S2KQFII2.mjs +0 -491
  121. package/dist/chunk-SLDK5PQK.mjs +0 -1129
  122. package/dist/chunk-SNSDVGWW.mjs +0 -783
  123. package/dist/chunk-SUUZMLPS.mjs +0 -391
  124. package/dist/chunk-SVCSIZ2A.mjs +0 -259
  125. package/dist/chunk-T2C6WS73.mjs +0 -670
  126. package/dist/chunk-TCG2G32F.mjs +0 -911
  127. package/dist/chunk-TGBZP7SB.mjs +0 -773
  128. package/dist/chunk-THF4RW63.mjs +0 -254
  129. package/dist/chunk-TJKDLVLN.mjs +0 -503
  130. package/dist/chunk-TXWPOVYU.mjs +0 -402
  131. package/dist/chunk-UB3CGOQ7.mjs +0 -64
  132. package/dist/chunk-UKIKN27B.mjs +0 -950
  133. package/dist/chunk-V5DP4FP6.mjs +0 -876
  134. package/dist/chunk-VRMXVYDZ.mjs +0 -419
  135. package/dist/chunk-WACZ5LFH.mjs +0 -1055
  136. package/dist/chunk-WC7CBAA7.mjs +0 -1058
  137. package/dist/chunk-WKBCNITM.mjs +0 -1072
  138. package/dist/chunk-WMOGJFME.mjs +0 -391
  139. package/dist/chunk-X4GR2N2M.mjs +0 -947
  140. package/dist/chunk-XCWY2DQY.mjs +0 -788
  141. package/dist/chunk-XJD35DS6.mjs +0 -1058
  142. package/dist/chunk-XNPID6FU.mjs +0 -391
  143. package/dist/chunk-XUUVS54V.mjs +0 -776
  144. package/dist/chunk-YCGV65F5.mjs +0 -508
  145. package/dist/chunk-YJYDBFT3.mjs +0 -780
  146. package/dist/chunk-YP3HEDQW.mjs +0 -859
  147. package/dist/chunk-YSDOUNJJ.mjs +0 -1142
  148. package/dist/chunk-Z6GBFFOV.mjs +0 -1040
  149. package/dist/cli.d.ts.map +0 -1
  150. package/dist/cli.js.map +0 -1
  151. package/dist/context-rules-entry-y2uJSngh.d.mts +0 -60
  152. package/dist/context-rules-entry-y2uJSngh.d.ts +0 -60
  153. package/dist/context-rules-entry.d.mts +0 -55
  154. package/dist/context-rules-entry.d.ts +0 -55
  155. package/dist/context-rules-entry.mjs +0 -12
  156. package/dist/context-rules.d.ts +0 -41
  157. package/dist/context-rules.d.ts.map +0 -1
  158. package/dist/context-rules.js +0 -225
  159. package/dist/context-rules.js.map +0 -1
  160. package/dist/detector-entry.d.mts +0 -14
  161. package/dist/detector-entry.d.ts +0 -14
  162. package/dist/detector-entry.js +0 -301
  163. package/dist/detector-entry.mjs +0 -7
  164. package/dist/detector.d.ts +0 -40
  165. package/dist/detector.d.ts.map +0 -1
  166. package/dist/detector.js +0 -385
  167. package/dist/detector.js.map +0 -1
  168. package/dist/extractors/python-extractor.d.ts +0 -19
  169. package/dist/extractors/python-extractor.d.ts.map +0 -1
  170. package/dist/extractors/python-extractor.js +0 -164
  171. package/dist/extractors/python-extractor.js.map +0 -1
  172. package/dist/grouping.d.ts +0 -54
  173. package/dist/grouping.d.ts.map +0 -1
  174. package/dist/grouping.js +0 -347
  175. package/dist/grouping.js.map +0 -1
  176. package/dist/index-y2uJSngh.d.mts +0 -60
  177. package/dist/index-y2uJSngh.d.ts +0 -60
  178. package/dist/index.d.ts.map +0 -1
  179. package/dist/index.js.map +0 -1
  180. package/dist/python-extractor-BGKGX6BK.mjs +0 -131
  181. package/dist/python-extractor-ELAKYK2W.mjs +0 -140
  182. package/dist/scoring-entry.d.mts +0 -23
  183. package/dist/scoring-entry.d.ts +0 -23
  184. package/dist/scoring-entry.mjs +0 -6
  185. package/dist/scoring.d.ts +0 -12
  186. package/dist/scoring.d.ts.map +0 -1
  187. package/dist/scoring.js +0 -116
  188. package/dist/scoring.js.map +0 -1
  189. package/dist/types-C4lmb2Yh.d.mts +0 -36
  190. package/dist/types-C4lmb2Yh.d.ts +0 -36
@@ -0,0 +1,283 @@
1
+ // src/context-rules.ts
2
+ import {
3
+ IssueType,
4
+ getSeverityLabel,
5
+ filterBySeverity,
6
+ Severity
7
+ } from "@aiready/core";
8
+ var CONTEXT_RULES = [
9
+ // Test Fixtures - Intentional duplication for test isolation
10
+ {
11
+ name: "test-fixtures",
12
+ detect: (file, code) => {
13
+ const isTestFile = file.includes(".test.") || file.includes(".spec.") || file.includes("__tests__") || file.includes("/test/") || file.includes("/tests/");
14
+ const hasTestFixtures = code.includes("beforeAll") || code.includes("afterAll") || code.includes("beforeEach") || code.includes("afterEach") || code.includes("setUp") || code.includes("tearDown");
15
+ return isTestFile && hasTestFixtures;
16
+ },
17
+ severity: Severity.Info,
18
+ reason: "Test fixture duplication is intentional for test isolation",
19
+ suggestion: "Consider if shared test setup would improve maintainability without coupling tests"
20
+ },
21
+ // Email/Document Templates - Often intentionally similar for consistency
22
+ {
23
+ name: "templates",
24
+ detect: (file, code) => {
25
+ const isTemplate = file.includes("/templates/") || file.includes("-template") || file.includes("/email-templates/") || file.includes("/emails/");
26
+ const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
27
+ return isTemplate && hasTemplateContent;
28
+ },
29
+ severity: Severity.Info,
30
+ reason: "Template duplication may be intentional for maintainability and branding consistency",
31
+ suggestion: "Extract shared structure only if templates become hard to maintain"
32
+ },
33
+ // E2E/Integration Test Page Objects - Test independence
34
+ {
35
+ name: "e2e-page-objects",
36
+ detect: (file, code) => {
37
+ const isE2ETest = file.includes("e2e/") || file.includes("/e2e/") || file.includes(".e2e.") || file.includes("/playwright/") || file.includes("playwright/") || file.includes("/cypress/") || file.includes("cypress/") || file.includes("/integration/") || file.includes("integration/");
38
+ const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
39
+ return isE2ETest && hasPageObjectPatterns;
40
+ },
41
+ severity: Severity.Info,
42
+ reason: "E2E test duplication ensures test independence and reduces coupling",
43
+ suggestion: "Consider page object pattern only if duplication causes maintenance issues"
44
+ },
45
+ // Configuration Files - Often necessarily similar by design
46
+ {
47
+ name: "config-files",
48
+ detect: (file) => {
49
+ return file.endsWith(".config.ts") || file.endsWith(".config.js") || file.includes("jest.config") || file.includes("vite.config") || file.includes("webpack.config") || file.includes("rollup.config") || file.includes("tsconfig");
50
+ },
51
+ severity: Severity.Info,
52
+ reason: "Configuration files often have similar structure by design",
53
+ suggestion: "Consider shared config base only if configurations become hard to maintain"
54
+ },
55
+ // Type Definitions - Duplication for type safety and module independence
56
+ // Matches type-only files OR interface/type definitions in component files
57
+ {
58
+ name: "type-definitions",
59
+ detect: (file, code) => {
60
+ const isTypeFile = file.endsWith(".d.ts") || file.includes("/types/");
61
+ const hasOnlyTypeDefinitions = (code.includes("interface ") || code.includes("type ") || code.includes("enum ")) && !code.includes("function ") && !code.includes("class ") && !code.includes("const ") && !code.includes("let ") && !code.includes("export default");
62
+ const isInterfaceOnlySnippet = code.trim().startsWith("interface ") && code.includes("{") && code.includes("}") && !code.includes("function ") && !code.includes("const ") && !code.includes("return ");
63
+ return isTypeFile && hasOnlyTypeDefinitions || isInterfaceOnlySnippet;
64
+ },
65
+ severity: Severity.Info,
66
+ reason: "Type/interface definitions are intentionally duplicated for module independence",
67
+ suggestion: "Extract to shared types package only if causing maintenance burden"
68
+ },
69
+ // Migration Scripts - One-off scripts that are similar by nature
70
+ {
71
+ name: "migration-scripts",
72
+ detect: (file) => {
73
+ return file.includes("/migrations/") || file.includes("/migrate/") || file.includes(".migration.");
74
+ },
75
+ severity: Severity.Info,
76
+ reason: "Migration scripts are typically one-off and intentionally similar",
77
+ suggestion: "Duplication is acceptable for migration scripts"
78
+ },
79
+ // Mock Data - Test data intentionally duplicated
80
+ {
81
+ name: "mock-data",
82
+ detect: (file, code) => {
83
+ const isMockFile = file.includes("/mocks/") || file.includes("/__mocks__/") || file.includes("/fixtures/") || file.includes(".mock.") || file.includes(".fixture.");
84
+ const hasMockData = code.includes("mock") || code.includes("Mock") || code.includes("fixture") || code.includes("stub") || code.includes("export const");
85
+ return isMockFile && hasMockData;
86
+ },
87
+ severity: Severity.Info,
88
+ reason: "Mock data duplication is expected for comprehensive test coverage",
89
+ suggestion: "Consider shared factories only for complex mock generation"
90
+ },
91
+ // Tool Implementations - Structural Boilerplate
92
+ {
93
+ name: "tool-implementations",
94
+ detect: (file, code) => {
95
+ const isToolFile = file.includes("/tools/") || file.endsWith(".tool.ts") || code.includes("toolDefinitions");
96
+ const hasToolStructure = code.includes("execute") && (code.includes("try") || code.includes("catch"));
97
+ return isToolFile && hasToolStructure;
98
+ },
99
+ severity: Severity.Info,
100
+ reason: "Tool implementations share structural boilerplate but have distinct business logic",
101
+ suggestion: "Tool duplication is acceptable for boilerplate interface wrappers"
102
+ },
103
+ // Common UI Event Handlers - Very specific patterns only
104
+ {
105
+ name: "common-ui-handlers",
106
+ detect: (file, code) => {
107
+ const isUIFile = file.includes("/components/") || file.includes(".tsx") || file.includes(".jsx") || file.includes("/hooks/");
108
+ const hasCommonHandler = code.includes("handleClickOutside") && code.includes("dropdownRef.current") && code.includes("!dropdownRef.current.contains") || code.includes("handleEscape") && code.includes("event.key") && code.includes("=== 'Escape'") || code.includes("handleClickInside") && code.includes("event.stopPropagation");
109
+ return isUIFile && hasCommonHandler;
110
+ },
111
+ severity: Severity.Info,
112
+ reason: "Common UI event handlers are boilerplate patterns that repeat across components",
113
+ suggestion: "Consider extracting to shared hooks (useClickOutside, useEscapeKey) only if causing maintenance issues"
114
+ },
115
+ // Utility Functions - Small helpers in dedicated utility files
116
+ {
117
+ name: "utility-functions",
118
+ detect: (file, code) => {
119
+ const isUtilFile = file.endsWith(".util.ts") || file.endsWith(".helper.ts") || file.endsWith(".utils.ts");
120
+ const hasUtilPattern = code.includes("function format") || code.includes("function parse") || code.includes("function sanitize") || code.includes("function normalize") || code.includes("function convert");
121
+ return isUtilFile && hasUtilPattern;
122
+ },
123
+ severity: Severity.Info,
124
+ reason: "Utility functions in dedicated utility files may be intentionally similar",
125
+ suggestion: "Consider extracting to shared utilities only if causing significant duplication"
126
+ },
127
+ // React/Vue Hooks - Standard patterns
128
+ {
129
+ name: "shared-hooks",
130
+ detect: (file, code) => {
131
+ const isHookFile = file.includes("/hooks/") || file.endsWith(".hook.ts") || file.endsWith(".hook.tsx");
132
+ const hasHookPattern = code.includes("function use") || code.includes("export function use") || code.includes("const use") || code.includes("export const use");
133
+ return isHookFile && hasHookPattern;
134
+ },
135
+ severity: Severity.Info,
136
+ reason: "Hooks follow standard patterns and are often intentionally similar across components",
137
+ suggestion: "Consider extracting common hook logic only if hooks become complex"
138
+ },
139
+ // CLI Command Definitions - Commander.js boilerplate patterns
140
+ {
141
+ name: "cli-command-definitions",
142
+ detect: (file, code) => {
143
+ const isCliFile = file.includes("/commands/") || file.includes("/cli/") || file.endsWith(".command.ts");
144
+ const hasCommandPattern = (code.includes(".command(") || code.includes("defineCommand")) && (code.includes(".description(") || code.includes(".option(")) && (code.includes(".action(") || code.includes("async"));
145
+ return isCliFile && hasCommandPattern;
146
+ },
147
+ severity: Severity.Info,
148
+ reason: "CLI command definitions follow standard Commander.js patterns and are intentionally similar",
149
+ suggestion: "Command boilerplate duplication is acceptable for CLI interfaces"
150
+ },
151
+ // Score/Rating Helper Functions - Common threshold patterns
152
+ {
153
+ name: "score-helpers",
154
+ detect: (file, code) => {
155
+ const isHelperFile = file.includes("/utils/") || file.includes("/helpers/") || file.endsWith(".util.ts");
156
+ const hasScorePattern = (code.includes("if (score >=") || code.includes("if (score >")) && code.includes("return") && code.includes("'") && code.split("if (score").length >= 3;
157
+ return isHelperFile && hasScorePattern;
158
+ },
159
+ severity: Severity.Info,
160
+ reason: "Score/rating helper functions use common threshold patterns that are intentionally similar",
161
+ suggestion: "Score formatting duplication is acceptable for consistent UI display"
162
+ },
163
+ // D3/Canvas Event Handlers - Standard visualization patterns
164
+ {
165
+ name: "visualization-handlers",
166
+ detect: (file, code) => {
167
+ const isVizFile = file.includes("/visualizer/") || file.includes("/charts/") || file.includes("GraphCanvas") || file.includes("ForceDirected");
168
+ const hasVizPattern = (code.includes("dragstarted") || code.includes("dragged") || code.includes("dragended")) && (code.includes("simulation") || code.includes("d3.") || code.includes("alphaTarget"));
169
+ return isVizFile && hasVizPattern;
170
+ },
171
+ severity: Severity.Info,
172
+ reason: "D3/visualization event handlers follow standard patterns and are intentionally similar",
173
+ suggestion: "Visualization boilerplate duplication is acceptable for interactive charts"
174
+ },
175
+ // Icon/Switch Statement Helpers - Common enum-to-value patterns
176
+ {
177
+ name: "switch-helpers",
178
+ detect: (file, code) => {
179
+ const hasSwitchPattern = code.includes("switch (") && code.includes("case '") && code.includes("return") && code.split("case ").length >= 4;
180
+ const hasIconPattern = code.includes("getIcon") || code.includes("getColor") || code.includes("getLabel") || code.includes("getRating");
181
+ return hasSwitchPattern && hasIconPattern;
182
+ },
183
+ severity: Severity.Info,
184
+ reason: "Switch statement helpers for enum-to-value mapping are inherently similar",
185
+ suggestion: "Switch duplication is acceptable for mapping enums to display values"
186
+ },
187
+ // Common API/Utility Functions - Legitimate duplication across modules
188
+ {
189
+ name: "common-api-functions",
190
+ detect: (file, code) => {
191
+ const isApiFile = file.includes("/api/") || file.includes("/lib/") || file.includes("/utils/") || file.endsWith(".ts");
192
+ const hasCommonApiPattern = code.includes("getStripe") && code.includes("process.env.STRIPE_SECRET_KEY") || code.includes("getUserByEmail") && code.includes("queryItems") || code.includes("updateUser") && code.includes("buildUpdateExpression") || code.includes("listUserRepositories") && code.includes("queryItems") || code.includes("listTeamRepositories") && code.includes("queryItems") || code.includes("getRemediation") && code.includes("queryItems") || code.includes("formatBreakdownKey") && code.includes(".replace(/([A-Z])/g") || code.includes("queryItems") && code.includes("KeyConditionExpression") || code.includes("putItem") && code.includes("createdAt") || code.includes("updateItem") && code.includes("buildUpdateExpression");
193
+ return isApiFile && hasCommonApiPattern;
194
+ },
195
+ severity: Severity.Info,
196
+ reason: "Common API/utility functions are legitimately duplicated across modules for clarity and independence",
197
+ suggestion: "Consider extracting to shared utilities only if causing significant duplication"
198
+ },
199
+ // Next.js Route Handler Patterns - Boilerplate API route patterns
200
+ {
201
+ name: "nextjs-route-handlers",
202
+ detect: (file, code) => {
203
+ const isRouteFile = file.includes("/api/") && (file.endsWith("/route.ts") || file.endsWith("/route.js"));
204
+ const hasRoutePattern = code.includes("export async function POST") || code.includes("export async function GET") || code.includes("export async function PUT") || code.includes("export async function DELETE") || code.includes("NextResponse.json") || code.includes("NextRequest");
205
+ return isRouteFile && hasRoutePattern;
206
+ },
207
+ severity: Severity.Info,
208
+ reason: "Next.js route handlers follow standard patterns and are intentionally similar across endpoints",
209
+ suggestion: "Route handler duplication is acceptable for API endpoint boilerplate"
210
+ },
211
+ // Validation Functions - Inherently similar patterns
212
+ {
213
+ name: "validation-functions",
214
+ detect: (file, code) => {
215
+ const hasValidationPattern = code.includes("isValid") || code.includes("validate") || code.includes("checkValid") || code.includes("isEmail") || code.includes("isPhone") || code.includes("isUrl") || code.includes("isNumeric") || code.includes("isAlpha") || code.includes("isAlphanumeric") || code.includes("isEmpty") || code.includes("isNotEmpty") || code.includes("isRequired") || code.includes("isOptional");
216
+ return hasValidationPattern;
217
+ },
218
+ severity: Severity.Info,
219
+ reason: "Validation functions are inherently similar and often intentionally duplicated for domain clarity",
220
+ suggestion: "Consider extracting to shared validators only if validation logic becomes complex"
221
+ }
222
+ ];
223
+ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
224
+ for (const rule of CONTEXT_RULES) {
225
+ if (rule.detect(file1, code) || rule.detect(file2, code)) {
226
+ return {
227
+ severity: rule.severity,
228
+ reason: rule.reason,
229
+ suggestion: rule.suggestion,
230
+ matchedRule: rule.name
231
+ };
232
+ }
233
+ }
234
+ if (similarity >= 0.95 && linesOfCode >= 30) {
235
+ return {
236
+ severity: Severity.Critical,
237
+ reason: "Large nearly-identical code blocks waste tokens and create maintenance burden",
238
+ suggestion: "Extract to shared utility module immediately"
239
+ };
240
+ } else if (similarity >= 0.95 && linesOfCode >= 15) {
241
+ return {
242
+ severity: Severity.Major,
243
+ reason: "Nearly identical code should be consolidated",
244
+ suggestion: "Move to shared utility file"
245
+ };
246
+ } else if (similarity >= 0.85) {
247
+ return {
248
+ severity: Severity.Major,
249
+ reason: "High similarity indicates significant duplication",
250
+ suggestion: "Extract common logic to shared function"
251
+ };
252
+ } else if (similarity >= 0.7) {
253
+ return {
254
+ severity: Severity.Minor,
255
+ reason: "Moderate similarity detected",
256
+ suggestion: "Consider extracting shared patterns if code evolves together"
257
+ };
258
+ } else {
259
+ return {
260
+ severity: Severity.Minor,
261
+ reason: "Minor similarity detected",
262
+ suggestion: "Monitor but refactoring may not be worthwhile"
263
+ };
264
+ }
265
+ }
266
+ function getSeverityThreshold(severity) {
267
+ const thresholds = {
268
+ [Severity.Critical]: 0.95,
269
+ [Severity.Major]: 0.85,
270
+ [Severity.Minor]: 0.5,
271
+ [Severity.Info]: 0
272
+ };
273
+ return thresholds[severity] || 0;
274
+ }
275
+
276
+ export {
277
+ IssueType,
278
+ getSeverityLabel,
279
+ filterBySeverity,
280
+ CONTEXT_RULES,
281
+ calculateSeverity,
282
+ getSeverityThreshold
283
+ };