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