@aiready/pattern-detect 0.17.14 → 0.17.16
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 +2 -2
- package/dist/analyzer-entry/index.d.ts +2 -2
- package/dist/analyzer-entry/index.js +391 -89
- package/dist/analyzer-entry/index.mjs +4 -4
- package/dist/chunk-3LMYFYWG.mjs +514 -0
- package/dist/chunk-4SKGAZEW.mjs +514 -0
- package/dist/chunk-4YXKUW4P.mjs +143 -0
- package/dist/chunk-5A3ULAQ5.mjs +571 -0
- package/dist/chunk-5FACKJ7M.mjs +519 -0
- package/dist/chunk-6B72OWZA.mjs +143 -0
- package/dist/chunk-6SHBBRHF.mjs +600 -0
- package/dist/chunk-ATXO4JL7.mjs +404 -0
- package/dist/chunk-BKSIA7A2.mjs +516 -0
- package/dist/chunk-CM5YJR7G.mjs +516 -0
- package/dist/chunk-F42Q2M4O.mjs +143 -0
- package/dist/chunk-FSXOU23F.mjs +620 -0
- package/dist/chunk-GUYQI3AF.mjs +514 -0
- package/dist/chunk-H2TGXGMX.mjs +587 -0
- package/dist/chunk-JWP5TCDM.mjs +143 -0
- package/dist/chunk-KDXWIT6W.mjs +408 -0
- package/dist/chunk-KMAOEVRS.mjs +150 -0
- package/dist/chunk-KZQXBBR3.mjs +143 -0
- package/dist/chunk-NVV4UFIV.mjs +514 -0
- package/dist/chunk-NWG2ZIGX.mjs +146 -0
- package/dist/chunk-OFVJFGQW.mjs +514 -0
- package/dist/chunk-PCCZREHY.mjs +143 -0
- package/dist/chunk-PFA2DO73.mjs +392 -0
- package/dist/chunk-PQS5ACTN.mjs +516 -0
- package/dist/chunk-TVE75IDM.mjs +143 -0
- package/dist/chunk-UDOGQ42Q.mjs +603 -0
- package/dist/chunk-UFI4UDQI.mjs +514 -0
- package/dist/chunk-UXV57HN3.mjs +144 -0
- package/dist/chunk-VC2BOV6R.mjs +143 -0
- package/dist/chunk-VI2OVG73.mjs +514 -0
- package/dist/chunk-VKGYNHFY.mjs +514 -0
- package/dist/chunk-WBLZYAQ2.mjs +518 -0
- package/dist/chunk-WFVXMMB3.mjs +143 -0
- package/dist/chunk-WQC43BIO.mjs +516 -0
- package/dist/chunk-WQX7IHAN.mjs +514 -0
- package/dist/chunk-WTAIM3SG.mjs +146 -0
- package/dist/chunk-XC7U55PE.mjs +514 -0
- package/dist/chunk-XR373Q6G.mjs +146 -0
- package/dist/chunk-XWIBTD67.mjs +620 -0
- package/dist/chunk-YUQ2VQVJ.mjs +514 -0
- package/dist/chunk-Z4NOH52X.mjs +143 -0
- package/dist/cli.js +395 -93
- package/dist/cli.mjs +8 -8
- package/dist/context-rules-entry/index.js +385 -88
- package/dist/context-rules-entry/index.mjs +1 -1
- package/dist/detector-entry/index.d.mts +2 -2
- package/dist/detector-entry/index.d.ts +2 -2
- package/dist/detector-entry/index.js +389 -89
- package/dist/detector-entry/index.mjs +2 -2
- package/dist/index-BGvkJ9j1.d.mts +136 -0
- package/dist/index-BJq32qmj.d.mts +137 -0
- package/dist/index-BpoJSgX-.d.mts +136 -0
- package/dist/index-C7qLPKmH.d.ts +150 -0
- package/dist/index-CThnG9hv.d.ts +155 -0
- package/dist/index-D0Hpg9nN.d.mts +150 -0
- package/dist/index-DN6XpBOW.d.mts +155 -0
- package/dist/index-F8xqZ2PS.d.ts +136 -0
- package/dist/index-HNhDr6CV.d.ts +137 -0
- package/dist/index-ux0Wo8Ps.d.ts +136 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +393 -91
- package/dist/index.mjs +6 -6
- package/dist/scoring-entry/index.d.mts +1 -1
- package/dist/scoring-entry/index.d.ts +1 -1
- package/dist/scoring-entry/index.js +2 -2
- package/dist/scoring-entry/index.mjs +1 -1
- package/dist/types-tgrmUrHE.d.mts +37 -0
- package/dist/types-tgrmUrHE.d.ts +37 -0
- package/package.json +8 -6
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { P as PatternDetectOptions, a as PatternSummary, b as analyzePatterns, i as generateSummary, k as getSmartDefaults } from '../index-
|
|
1
|
+
export { P as PatternDetectOptions, a as PatternSummary, b as analyzePatterns, i as generateSummary, k as getSmartDefaults } from '../index-DN6XpBOW.mjs';
|
|
2
2
|
import '@aiready/core';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-tgrmUrHE.mjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { P as PatternDetectOptions, a as PatternSummary, b as analyzePatterns, i as generateSummary, k as getSmartDefaults } from '../index-
|
|
1
|
+
export { P as PatternDetectOptions, a as PatternSummary, b as analyzePatterns, i as generateSummary, k as getSmartDefaults } from '../index-CThnG9hv.js';
|
|
2
2
|
import '@aiready/core';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-tgrmUrHE.js';
|
|
@@ -174,124 +174,421 @@ var INFRA_RULES = [
|
|
|
174
174
|
severity: import_core3.Severity.Info,
|
|
175
175
|
reason: "CLI command definitions follow standard Commander.js patterns and are intentionally similar",
|
|
176
176
|
suggestion: "Command boilerplate duplication is acceptable for CLI interfaces"
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// src/rules/categories/logic-rules.ts
|
|
181
|
-
var import_core4 = require("@aiready/core");
|
|
182
|
-
var LOGIC_RULES = [
|
|
183
|
-
// Re-export / Barrel files - Intentional API surface consolidation
|
|
177
|
+
},
|
|
178
|
+
// DynamoDB Single-Table Design - Standard single-table patterns with prefixed keys
|
|
184
179
|
{
|
|
185
|
-
name: "
|
|
180
|
+
name: "dynamodb-single-table",
|
|
186
181
|
detect: (file, code) => {
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
(l) => /^export\s+(\{[^}]+\}|\*)\s+from\s+/.test(l.trim()) || /^export\s+\*\s+as\s+\w+\s+from\s+/.test(l.trim())
|
|
192
|
-
).length;
|
|
193
|
-
return isIndexFile && reExportLines > 0 && reExportLines / lines.length > 0.5;
|
|
182
|
+
const hasDynamoDBPattern = code.includes("docClient") || code.includes("dynamodb") || code.includes("DynamoDB") || code.includes("queryItems") || code.includes("putItem") || code.includes("getItem") || code.includes("updateItem") || code.includes("deleteItem");
|
|
183
|
+
const hasKeyPrefix = code.includes("userId:") && code.includes("#") || code.includes("pk:") && code.includes("#") || code.includes("Key:") && code.includes("#") || /[A-Z]+#/.test(code);
|
|
184
|
+
const hasSingleTablePattern = code.includes("KeyConditionExpression") || code.includes("pk =") || code.includes("sk =") || code.includes("userId") && code.includes("timestamp");
|
|
185
|
+
return hasDynamoDBPattern && (hasKeyPrefix || hasSingleTablePattern);
|
|
194
186
|
},
|
|
195
|
-
severity:
|
|
196
|
-
reason: "
|
|
197
|
-
suggestion: "
|
|
187
|
+
severity: import_core3.Severity.Info,
|
|
188
|
+
reason: "DynamoDB single-table design with prefixed keys is a standard pattern for efficient data access",
|
|
189
|
+
suggestion: "Single-table query patterns are intentionally similar and should not be refactored"
|
|
198
190
|
},
|
|
199
|
-
//
|
|
191
|
+
// CLI Main Function Boilerplate - Standard argument parsing patterns
|
|
200
192
|
{
|
|
201
|
-
name: "
|
|
193
|
+
name: "cli-main-boilerplate",
|
|
202
194
|
detect: (file, code) => {
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
195
|
+
const basename = file.split("/").pop() || "";
|
|
196
|
+
const isCliFile = file.includes("/cli/") || file.includes("/commands/") || basename.startsWith("cli") || basename.endsWith(".cli.ts") || basename.endsWith(".cli.js");
|
|
197
|
+
const hasMainFunction = code.includes("function main()") || code.includes("async function main()") || code.includes("const main =") || code.includes("main()");
|
|
198
|
+
const hasArgParsing = code.includes("process.argv") || code.includes("yargs") || code.includes("commander") || code.includes("minimist") || code.includes(".parse(") || code.includes("args") && code.includes("._");
|
|
199
|
+
return isCliFile && hasMainFunction && hasArgParsing;
|
|
207
200
|
},
|
|
201
|
+
severity: import_core3.Severity.Info,
|
|
202
|
+
reason: "CLI main functions with argument parsing follow standard boilerplate patterns",
|
|
203
|
+
suggestion: "CLI argument parsing boilerplate is acceptable and should not be flagged as duplication"
|
|
204
|
+
}
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
// src/rules/categories/logic/file-detectors.ts
|
|
208
|
+
var FileDetectors = {
|
|
209
|
+
isIndexFile: (file) => file.endsWith("/index.ts") || file.endsWith("/index.js") || file.endsWith("/index.tsx") || file.endsWith("/index.jsx"),
|
|
210
|
+
isTypeFile: (file) => file.endsWith(".d.ts") || file.includes("/types/"),
|
|
211
|
+
isUtilFile: (file) => file.endsWith(".util.ts") || file.endsWith(".helper.ts") || file.endsWith(".utils.ts"),
|
|
212
|
+
isHookFile: (file) => file.includes("/hooks/") || file.endsWith(".hook.ts") || file.endsWith(".hook.tsx"),
|
|
213
|
+
isHelperFile: (file) => file.includes("/utils/") || file.includes("/helpers/") || file.endsWith(".util.ts"),
|
|
214
|
+
isVizFile: (file) => file.includes("/visualizer/") || file.includes("/charts/") || file.includes("GraphCanvas") || file.includes("ForceDirected"),
|
|
215
|
+
isApiFile: (file) => file.includes("/api/") || file.includes("/lib/") || file.includes("/utils/") || file.endsWith(".ts"),
|
|
216
|
+
isPackageOrApp: (file) => file.includes("/packages/") || file.includes("/apps/") || file.includes("/core/"),
|
|
217
|
+
getPackageName: (file) => {
|
|
218
|
+
const match = file.match(/\/(packages|apps|core)\/([^/]+)\//);
|
|
219
|
+
return match?.[2] || null;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/rules/categories/logic/keyword-lists.ts
|
|
224
|
+
var VALIDATION_KEYWORDS = [
|
|
225
|
+
"isValid",
|
|
226
|
+
"validate",
|
|
227
|
+
"checkValid",
|
|
228
|
+
"isEmail",
|
|
229
|
+
"isPhone",
|
|
230
|
+
"isUrl",
|
|
231
|
+
"isNumeric",
|
|
232
|
+
"isAlpha",
|
|
233
|
+
"isAlphanumeric",
|
|
234
|
+
"isEmpty",
|
|
235
|
+
"isNotEmpty",
|
|
236
|
+
"isRequired",
|
|
237
|
+
"isOptional"
|
|
238
|
+
];
|
|
239
|
+
var HOOK_KEYWORDS = [
|
|
240
|
+
"function use",
|
|
241
|
+
"export function use",
|
|
242
|
+
"const use",
|
|
243
|
+
"export const use"
|
|
244
|
+
];
|
|
245
|
+
var VIZ_EVENT_KEYWORDS = ["dragstarted", "dragged", "dragended"];
|
|
246
|
+
var VIZ_LIB_KEYWORDS = ["simulation", "d3.", "alphaTarget"];
|
|
247
|
+
var ICON_HELPER_KEYWORDS = [
|
|
248
|
+
"getIcon",
|
|
249
|
+
"getColor",
|
|
250
|
+
"getLabel",
|
|
251
|
+
"getRating"
|
|
252
|
+
];
|
|
253
|
+
var UTIL_KEYWORDS = [
|
|
254
|
+
"format",
|
|
255
|
+
"parse",
|
|
256
|
+
"sanitize",
|
|
257
|
+
"normalize",
|
|
258
|
+
"convert",
|
|
259
|
+
"utility",
|
|
260
|
+
"helper"
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
// src/rules/categories/logic/detectors.ts
|
|
264
|
+
var isEnumDefinition = (code) => /(?:export\s+)?(?:const\s+)?enum\s+/.test(code) || code.includes("enum ") && code.includes("{") && code.includes("}");
|
|
265
|
+
var hasSingletonGetter = (code) => /(?:export\s+)?(?:async\s+)?function\s+get[A-Z][a-zA-Z0-9]*\s*\(/.test(
|
|
266
|
+
code
|
|
267
|
+
) || /(?:export\s+)?const\s+get[A-Z][a-zA-Z0-9]*\s*=\s*(?:async\s+)?\(\)\s*=>/.test(
|
|
268
|
+
code
|
|
269
|
+
);
|
|
270
|
+
var hasSingletonPattern = (code) => code.includes("if (!") && code.includes("instance") && code.includes(" = ") || code.includes("if (!_") && code.includes(" = new ");
|
|
271
|
+
var hasReExportPattern = (code) => {
|
|
272
|
+
const lines = code.split("\n").filter((l) => l.trim());
|
|
273
|
+
if (lines.length === 0) return false;
|
|
274
|
+
const reExportLines = lines.filter(
|
|
275
|
+
(l) => /^export\s+(\{[^}]+\}|\*)\s+from\s+/.test(l.trim()) || /^export\s+\*\s+as\s+\w+\s+from\s+/.test(l.trim())
|
|
276
|
+
).length;
|
|
277
|
+
return reExportLines > 0 && reExportLines / lines.length > 0.5;
|
|
278
|
+
};
|
|
279
|
+
var isInterfaceOnlySnippet = (code) => {
|
|
280
|
+
const hasInterface = code.includes("interface ");
|
|
281
|
+
const hasType = code.includes("type ");
|
|
282
|
+
const hasEnum = code.includes("enum ");
|
|
283
|
+
const hasNoImpl = ![
|
|
284
|
+
"function ",
|
|
285
|
+
"class ",
|
|
286
|
+
"const ",
|
|
287
|
+
"let ",
|
|
288
|
+
"var ",
|
|
289
|
+
"export default",
|
|
290
|
+
"export {"
|
|
291
|
+
].some((kw) => code.includes(kw));
|
|
292
|
+
return (hasInterface || hasType || hasEnum) && hasNoImpl;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/rules/categories/logic/code-patterns.ts
|
|
296
|
+
var COMMON_ENUM_PATTERNS = [
|
|
297
|
+
["LOW", ["'low'", "0", "'LOW'"]],
|
|
298
|
+
["HIGH", ["'high'", "2", "'HIGH'"]],
|
|
299
|
+
["MEDIUM", ["'medium'", "1", "'MEDIUM'"]]
|
|
300
|
+
];
|
|
301
|
+
var hasEnumValue = (code, enumName, variants) => variants.some((v) => code.includes(`${enumName} = ${v}`));
|
|
302
|
+
var CodePatterns = {
|
|
303
|
+
// Enum patterns
|
|
304
|
+
hasCommonEnumValues: (code) => COMMON_ENUM_PATTERNS.every(
|
|
305
|
+
([name, variants]) => hasEnumValue(code, name, variants)
|
|
306
|
+
),
|
|
307
|
+
isEnumDefinition,
|
|
308
|
+
// Type patterns - helpers for checking type-only definitions
|
|
309
|
+
hasTypeDefinition: (code) => code.includes("interface ") || code.includes("type ") || code.includes("enum "),
|
|
310
|
+
isTypeOnlyFile: (code) => {
|
|
311
|
+
const hasTypes = CodePatterns.hasTypeDefinition(code);
|
|
312
|
+
const hasNoImpl = ![
|
|
313
|
+
"function ",
|
|
314
|
+
"class ",
|
|
315
|
+
"const ",
|
|
316
|
+
"let ",
|
|
317
|
+
"export default"
|
|
318
|
+
].some((kw) => code.includes(kw));
|
|
319
|
+
return hasTypes && hasNoImpl;
|
|
320
|
+
},
|
|
321
|
+
hasOnlyTypeDefinitions: (code) => {
|
|
322
|
+
const hasTypes = CodePatterns.hasTypeDefinition(code);
|
|
323
|
+
const hasNoImpl = ![
|
|
324
|
+
"function ",
|
|
325
|
+
"class ",
|
|
326
|
+
"const ",
|
|
327
|
+
"let ",
|
|
328
|
+
"var ",
|
|
329
|
+
"export default",
|
|
330
|
+
"export {"
|
|
331
|
+
].some((kw) => code.includes(kw));
|
|
332
|
+
return hasTypes && hasNoImpl;
|
|
333
|
+
},
|
|
334
|
+
// Utility patterns - function group patterns
|
|
335
|
+
hasUtilPattern: (code) => CodePatterns.hasFunctionGroup(code, "") || CodePatterns.hasKeywordGroup(code, UTIL_KEYWORDS),
|
|
336
|
+
hasFunctionGroup: (code, prefix) => {
|
|
337
|
+
const regex = new RegExp(
|
|
338
|
+
`${prefix}(format|parse|sanitize|normalize|convert)`,
|
|
339
|
+
"i"
|
|
340
|
+
);
|
|
341
|
+
return regex.test(code);
|
|
342
|
+
},
|
|
343
|
+
// Pattern checkers using keyword lists
|
|
344
|
+
hasKeywordGroup: (code, keywords) => keywords.some((kw) => code.includes(kw)),
|
|
345
|
+
// Validation patterns - unified keyword check
|
|
346
|
+
hasValidationPattern: (code) => CodePatterns.hasKeywordGroup(code, VALIDATION_KEYWORDS),
|
|
347
|
+
// Hook patterns - React/Vue hooks
|
|
348
|
+
hasHookPattern: (code) => CodePatterns.hasKeywordGroup(code, HOOK_KEYWORDS),
|
|
349
|
+
// Score/Rating patterns
|
|
350
|
+
hasScorePattern: (code) => (code.includes("if (score >=") || code.includes("if (score >")) && code.includes("return") && code.includes("'") && code.split("if (score").length >= 3,
|
|
351
|
+
// Visualization patterns - D3/Canvas
|
|
352
|
+
hasVizPattern: (code) => CodePatterns.hasKeywordGroup(code, VIZ_EVENT_KEYWORDS) && CodePatterns.hasKeywordGroup(code, VIZ_LIB_KEYWORDS),
|
|
353
|
+
// Switch/Icon patterns
|
|
354
|
+
hasSwitchPattern: (code) => code.includes("switch (") && code.includes("case '") && code.includes("return") && code.split("case ").length >= 4,
|
|
355
|
+
hasIconPattern: (code) => CodePatterns.hasKeywordGroup(code, ICON_HELPER_KEYWORDS),
|
|
356
|
+
// Singleton patterns
|
|
357
|
+
hasSingletonGetter,
|
|
358
|
+
hasSingletonPattern,
|
|
359
|
+
// Re-export patterns
|
|
360
|
+
hasReExportPattern,
|
|
361
|
+
// Interface-only snippets
|
|
362
|
+
isInterfaceOnlySnippet
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/rules/categories/logic/api-patterns.ts
|
|
366
|
+
var API_PATTERNS = {
|
|
367
|
+
stripe: {
|
|
368
|
+
functions: ["getStripe"],
|
|
369
|
+
keywords: ["process.env.STRIPE_SECRET_KEY"]
|
|
370
|
+
},
|
|
371
|
+
userManagement: {
|
|
372
|
+
functions: ["getUserByEmail"],
|
|
373
|
+
keywords: ["queryItems"]
|
|
374
|
+
},
|
|
375
|
+
userUpdate: {
|
|
376
|
+
functions: ["updateUser"],
|
|
377
|
+
keywords: ["buildUpdateExpression"]
|
|
378
|
+
},
|
|
379
|
+
repositoryListing: {
|
|
380
|
+
functions: ["listUserRepositories", "listTeamRepositories"],
|
|
381
|
+
keywords: ["queryItems"]
|
|
382
|
+
},
|
|
383
|
+
remediationQueries: {
|
|
384
|
+
functions: ["getRemediation"],
|
|
385
|
+
keywords: ["queryItems"]
|
|
386
|
+
},
|
|
387
|
+
keyFormatting: {
|
|
388
|
+
functions: ["formatBreakdownKey"],
|
|
389
|
+
keywords: [".replace(/([A-Z])/g"]
|
|
390
|
+
},
|
|
391
|
+
dynamoDbQueries: {
|
|
392
|
+
functions: ["queryItems"],
|
|
393
|
+
keywords: ["KeyConditionExpression"]
|
|
394
|
+
},
|
|
395
|
+
itemOperations: {
|
|
396
|
+
functions: ["putItem"],
|
|
397
|
+
keywords: ["createdAt"]
|
|
398
|
+
},
|
|
399
|
+
itemUpdates: {
|
|
400
|
+
functions: ["updateItem"],
|
|
401
|
+
keywords: ["buildUpdateExpression"]
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
var ApiPatterns = {
|
|
405
|
+
/**
|
|
406
|
+
* Check if code contains a common API pattern
|
|
407
|
+
* Reduces from 11 separate || conditions to single call
|
|
408
|
+
*/
|
|
409
|
+
hasCommonApiPattern: (code) => {
|
|
410
|
+
for (const pattern of Object.values(API_PATTERNS)) {
|
|
411
|
+
const hasFunctions = pattern.functions.some((fn) => code.includes(fn));
|
|
412
|
+
const hasKeywords = pattern.keywords.some((kw) => code.includes(kw));
|
|
413
|
+
if (hasFunctions && hasKeywords) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
},
|
|
419
|
+
/**
|
|
420
|
+
* Get all API patterns (useful for documentation/analysis)
|
|
421
|
+
*/
|
|
422
|
+
getPatterns: () => API_PATTERNS,
|
|
423
|
+
/**
|
|
424
|
+
* Check if code matches a specific API pattern by name
|
|
425
|
+
*/
|
|
426
|
+
matchesPattern: (code, patternName) => {
|
|
427
|
+
const pattern = API_PATTERNS[patternName];
|
|
428
|
+
if (!pattern) return false;
|
|
429
|
+
const hasFunctions = pattern.functions.some((fn) => code.includes(fn));
|
|
430
|
+
const hasKeywords = pattern.keywords.some((kw) => code.includes(kw));
|
|
431
|
+
return hasFunctions && hasKeywords;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/rules/categories/logic/rule-builders.ts
|
|
436
|
+
var import_core4 = require("@aiready/core");
|
|
437
|
+
function createRule(config) {
|
|
438
|
+
return {
|
|
439
|
+
name: config.name,
|
|
440
|
+
detect: config.detect,
|
|
441
|
+
severity: config.severity || import_core4.Severity.Info,
|
|
442
|
+
reason: config.reason,
|
|
443
|
+
suggestion: config.suggestion
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
var RuleTemplates = {
|
|
447
|
+
// Type-related rules
|
|
448
|
+
typeDefinition: {
|
|
208
449
|
severity: import_core4.Severity.Info,
|
|
209
450
|
reason: "Type/interface definitions are intentionally duplicated for module independence",
|
|
210
451
|
suggestion: "Extract to shared types package only if causing maintenance burden"
|
|
211
452
|
},
|
|
212
|
-
|
|
213
|
-
{
|
|
214
|
-
name: "utility-functions",
|
|
215
|
-
detect: (file, code) => {
|
|
216
|
-
const isUtilFile = file.endsWith(".util.ts") || file.endsWith(".helper.ts") || file.endsWith(".utils.ts");
|
|
217
|
-
const hasUtilPattern = code.includes("function format") || code.includes("function parse") || code.includes("function sanitize") || code.includes("function normalize") || code.includes("function convert");
|
|
218
|
-
return isUtilFile && hasUtilPattern;
|
|
219
|
-
},
|
|
453
|
+
crossPackageType: {
|
|
220
454
|
severity: import_core4.Severity.Info,
|
|
221
|
-
reason: "
|
|
455
|
+
reason: "Types in different packages/modules are often intentionally similar for module independence",
|
|
456
|
+
suggestion: "Cross-package type duplication is acceptable for decoupled module architecture"
|
|
457
|
+
},
|
|
458
|
+
// Pattern rules
|
|
459
|
+
standardPatterns: {
|
|
460
|
+
severity: import_core4.Severity.Info,
|
|
461
|
+
reason: "This pattern is inherently similar and intentionally duplicated across modules",
|
|
462
|
+
suggestion: "Pattern duplication is acceptable for domain clarity and independence"
|
|
463
|
+
},
|
|
464
|
+
// API rules
|
|
465
|
+
commonApiFunction: {
|
|
466
|
+
severity: import_core4.Severity.Info,
|
|
467
|
+
reason: "Common API/utility functions are legitimately duplicated across modules for clarity and independence",
|
|
222
468
|
suggestion: "Consider extracting to shared utilities only if causing significant duplication"
|
|
223
469
|
},
|
|
224
|
-
//
|
|
225
|
-
{
|
|
226
|
-
|
|
470
|
+
// Utility rules
|
|
471
|
+
utilityFunction: {
|
|
472
|
+
severity: import_core4.Severity.Info,
|
|
473
|
+
reason: "Utility functions may be intentionally similar across modules",
|
|
474
|
+
suggestion: "Consider extracting to shared utilities only if causing significant duplication"
|
|
475
|
+
},
|
|
476
|
+
// Boilerplate rules
|
|
477
|
+
boilerplate: {
|
|
478
|
+
severity: import_core4.Severity.Info,
|
|
479
|
+
reason: "This pattern is boilerplate and acceptable duplication",
|
|
480
|
+
suggestion: "Boilerplate reduction is acceptable for standard patterns"
|
|
481
|
+
},
|
|
482
|
+
// Enum rules
|
|
483
|
+
enumSemantic: {
|
|
484
|
+
severity: import_core4.Severity.Info,
|
|
485
|
+
reason: "Enums with different names represent different semantic domain concepts, even if they share similar values",
|
|
486
|
+
suggestion: "Different enums (e.g., EscalationPriority vs HealthSeverity) serve different purposes and should not be merged"
|
|
487
|
+
},
|
|
488
|
+
enumValue: {
|
|
489
|
+
severity: import_core4.Severity.Info,
|
|
490
|
+
reason: "Common enum values (LOW, MEDIUM, HIGH, CRITICAL) are standard patterns used across different domain enums",
|
|
491
|
+
suggestion: "Enum value similarity is expected for severity/priority enums and should not be flagged as duplication"
|
|
492
|
+
},
|
|
493
|
+
// Barrel file rules
|
|
494
|
+
barrelFile: {
|
|
495
|
+
severity: import_core4.Severity.Info,
|
|
496
|
+
reason: "Barrel/index files intentionally re-export for API surface consolidation",
|
|
497
|
+
suggestion: "Re-exports in barrel files are expected and not true duplication"
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/rules/categories/logic-rules.ts
|
|
502
|
+
var LOGIC_RULES = [
|
|
503
|
+
// Enum patterns - identify by semantic meaning and value patterns
|
|
504
|
+
createRule({
|
|
505
|
+
name: "enum-semantic-difference",
|
|
506
|
+
detect: (file, code) => CodePatterns.isEnumDefinition(code),
|
|
507
|
+
...RuleTemplates.enumSemantic
|
|
508
|
+
}),
|
|
509
|
+
createRule({
|
|
510
|
+
name: "enum-value-similarity",
|
|
511
|
+
detect: (file, code) => CodePatterns.hasCommonEnumValues(code) && CodePatterns.isEnumDefinition(code),
|
|
512
|
+
...RuleTemplates.enumValue
|
|
513
|
+
}),
|
|
514
|
+
// Barrel/re-export files - intentional API consolidation
|
|
515
|
+
createRule({
|
|
516
|
+
name: "re-export-files",
|
|
517
|
+
detect: (file, code) => FileDetectors.isIndexFile(file) && CodePatterns.hasReExportPattern(code),
|
|
518
|
+
...RuleTemplates.barrelFile
|
|
519
|
+
}),
|
|
520
|
+
// Type definitions - consolidated rule for both local and cross-package types
|
|
521
|
+
// PHASE 2 CONSOLIDATION: merged type-definitions + cross-package-types
|
|
522
|
+
createRule({
|
|
523
|
+
name: "type-definitions",
|
|
227
524
|
detect: (file, code) => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
525
|
+
if (FileDetectors.isTypeFile(file)) {
|
|
526
|
+
if (CodePatterns.hasOnlyTypeDefinitions(code)) return true;
|
|
527
|
+
}
|
|
528
|
+
if (CodePatterns.isInterfaceOnlySnippet(code)) return true;
|
|
529
|
+
if (FileDetectors.isPackageOrApp(file) && FileDetectors.getPackageName(file) !== null && CodePatterns.hasTypeDefinition(code)) {
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
231
533
|
},
|
|
232
|
-
|
|
534
|
+
reason: "Type/interface definitions are intentionally duplicated for module independence and decoupled module architecture",
|
|
535
|
+
suggestion: "Extract to shared types package only if causing significant maintenance burden or cross-package conflicts"
|
|
536
|
+
}),
|
|
537
|
+
// Utility functions - dedicated utility file patterns
|
|
538
|
+
createRule({
|
|
539
|
+
name: "utility-functions",
|
|
540
|
+
detect: (file, code) => FileDetectors.isUtilFile(file) && CodePatterns.hasUtilPattern(code),
|
|
541
|
+
...RuleTemplates.utilityFunction
|
|
542
|
+
}),
|
|
543
|
+
// React/Vue Hooks - standard hook patterns
|
|
544
|
+
createRule({
|
|
545
|
+
name: "shared-hooks",
|
|
546
|
+
detect: (file, code) => FileDetectors.isHookFile(file) && CodePatterns.hasHookPattern(code),
|
|
233
547
|
reason: "Hooks follow standard patterns and are often intentionally similar across components",
|
|
234
548
|
suggestion: "Consider extracting common hook logic only if hooks become complex"
|
|
235
|
-
},
|
|
236
|
-
// Score/Rating
|
|
237
|
-
{
|
|
549
|
+
}),
|
|
550
|
+
// Score/Rating helpers - common threshold patterns
|
|
551
|
+
createRule({
|
|
238
552
|
name: "score-helpers",
|
|
239
|
-
detect: (file, code) =>
|
|
240
|
-
const isHelperFile = file.includes("/utils/") || file.includes("/helpers/") || file.endsWith(".util.ts");
|
|
241
|
-
const hasScorePattern = (code.includes("if (score >=") || code.includes("if (score >")) && code.includes("return") && code.includes("'") && code.split("if (score").length >= 3;
|
|
242
|
-
return isHelperFile && hasScorePattern;
|
|
243
|
-
},
|
|
244
|
-
severity: import_core4.Severity.Info,
|
|
553
|
+
detect: (file, code) => (FileDetectors.isHelperFile(file) || file.includes("/utils/")) && CodePatterns.hasScorePattern(code),
|
|
245
554
|
reason: "Score/rating helper functions use common threshold patterns that are intentionally similar",
|
|
246
555
|
suggestion: "Score formatting duplication is acceptable for consistent UI display"
|
|
247
|
-
},
|
|
248
|
-
// D3/Canvas
|
|
249
|
-
{
|
|
556
|
+
}),
|
|
557
|
+
// D3/Canvas event handlers - visualization patterns
|
|
558
|
+
createRule({
|
|
250
559
|
name: "visualization-handlers",
|
|
251
|
-
detect: (file, code) =>
|
|
252
|
-
const isVizFile = file.includes("/visualizer/") || file.includes("/charts/") || file.includes("GraphCanvas") || file.includes("ForceDirected");
|
|
253
|
-
const hasVizPattern = (code.includes("dragstarted") || code.includes("dragged") || code.includes("dragended")) && (code.includes("simulation") || code.includes("d3.") || code.includes("alphaTarget"));
|
|
254
|
-
return isVizFile && hasVizPattern;
|
|
255
|
-
},
|
|
256
|
-
severity: import_core4.Severity.Info,
|
|
560
|
+
detect: (file, code) => FileDetectors.isVizFile(file) && CodePatterns.hasVizPattern(code),
|
|
257
561
|
reason: "D3/visualization event handlers follow standard patterns and are intentionally similar",
|
|
258
562
|
suggestion: "Visualization boilerplate duplication is acceptable for interactive charts"
|
|
259
|
-
},
|
|
260
|
-
//
|
|
261
|
-
{
|
|
563
|
+
}),
|
|
564
|
+
// Switch statement helpers - enum-to-value mapping
|
|
565
|
+
createRule({
|
|
262
566
|
name: "switch-helpers",
|
|
263
|
-
detect: (file, code) =>
|
|
264
|
-
const hasSwitchPattern = code.includes("switch (") && code.includes("case '") && code.includes("return") && code.split("case ").length >= 4;
|
|
265
|
-
const hasIconPattern = code.includes("getIcon") || code.includes("getColor") || code.includes("getLabel") || code.includes("getRating");
|
|
266
|
-
return hasSwitchPattern && hasIconPattern;
|
|
267
|
-
},
|
|
268
|
-
severity: import_core4.Severity.Info,
|
|
567
|
+
detect: (file, code) => CodePatterns.hasSwitchPattern(code) && CodePatterns.hasIconPattern(code),
|
|
269
568
|
reason: "Switch statement helpers for enum-to-value mapping are inherently similar",
|
|
270
569
|
suggestion: "Switch duplication is acceptable for mapping enums to display values"
|
|
271
|
-
},
|
|
272
|
-
// Common API/Utility
|
|
273
|
-
{
|
|
570
|
+
}),
|
|
571
|
+
// Common API/Utility functions - legitimately duplicated across modules
|
|
572
|
+
createRule({
|
|
274
573
|
name: "common-api-functions",
|
|
275
|
-
detect: (file, code) =>
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
reason: "Common API/utility functions are legitimately duplicated across modules for clarity and independence",
|
|
282
|
-
suggestion: "Consider extracting to shared utilities only if causing significant duplication"
|
|
283
|
-
},
|
|
284
|
-
// Validation Functions - Inherently similar patterns
|
|
285
|
-
{
|
|
574
|
+
detect: (file, code) => FileDetectors.isApiFile(file) && ApiPatterns.hasCommonApiPattern(code),
|
|
575
|
+
...RuleTemplates.commonApiFunction
|
|
576
|
+
}),
|
|
577
|
+
// Validation functions - inherently similar patterns
|
|
578
|
+
// PHASE 2: Consolidated validation-function branches into single rule
|
|
579
|
+
createRule({
|
|
286
580
|
name: "validation-functions",
|
|
287
|
-
detect: (file, code) =>
|
|
288
|
-
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");
|
|
289
|
-
return hasValidationPattern;
|
|
290
|
-
},
|
|
291
|
-
severity: import_core4.Severity.Info,
|
|
581
|
+
detect: (file, code) => CodePatterns.hasValidationPattern(code),
|
|
292
582
|
reason: "Validation functions are inherently similar and often intentionally duplicated for domain clarity",
|
|
293
583
|
suggestion: "Consider extracting to shared validators only if validation logic becomes complex"
|
|
294
|
-
}
|
|
584
|
+
}),
|
|
585
|
+
// Singleton getter pattern - standard initialization
|
|
586
|
+
createRule({
|
|
587
|
+
name: "singleton-getter",
|
|
588
|
+
detect: (file, code) => CodePatterns.hasSingletonGetter(code) && CodePatterns.hasSingletonPattern(code),
|
|
589
|
+
reason: "Singleton getter functions follow standard initialization pattern and are intentionally similar",
|
|
590
|
+
suggestion: "Singleton getters are boilerplate and acceptable duplication for lazy initialization"
|
|
591
|
+
})
|
|
295
592
|
];
|
|
296
593
|
|
|
297
594
|
// src/context-rules.ts
|
|
@@ -324,7 +621,7 @@ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
|
324
621
|
reason: "Nearly identical code should be consolidated",
|
|
325
622
|
suggestion: "Move to shared utility file"
|
|
326
623
|
};
|
|
327
|
-
} else if (similarity >= 0.85) {
|
|
624
|
+
} else if (similarity >= 0.85 && linesOfCode >= 10) {
|
|
328
625
|
return {
|
|
329
626
|
severity: import_core5.Severity.Major,
|
|
330
627
|
reason: "High similarity indicates significant duplication",
|
|
@@ -378,7 +675,10 @@ async function detectDuplicatePatterns(fileContents, options) {
|
|
|
378
675
|
ignoreWhitelist = []
|
|
379
676
|
} = options;
|
|
380
677
|
const allBlocks = [];
|
|
381
|
-
const
|
|
678
|
+
const regexStr = (f) => f.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, "[^/]*").replace(/\[\^\/\]\*\[\^\/\]\*/g, ".*");
|
|
679
|
+
const excludeRegexes = excludePatterns.map(
|
|
680
|
+
(p) => new RegExp(`${regexStr(p)}$`, "i")
|
|
681
|
+
);
|
|
382
682
|
for (const { file, content } of fileContents) {
|
|
383
683
|
const blocks = extractBlocks(file, content);
|
|
384
684
|
for (const b of blocks) {
|
|
@@ -867,6 +1167,7 @@ async function analyzePatterns(options) {
|
|
|
867
1167
|
minClusterTokenCost = 1e3,
|
|
868
1168
|
minClusterFiles = 3,
|
|
869
1169
|
excludePatterns = [],
|
|
1170
|
+
excludeFiles = [],
|
|
870
1171
|
confidenceThreshold = 0,
|
|
871
1172
|
ignoreWhitelist = [],
|
|
872
1173
|
...scanOptions
|
|
@@ -896,6 +1197,7 @@ async function analyzePatterns(options) {
|
|
|
896
1197
|
maxCandidatesPerBlock,
|
|
897
1198
|
streamResults,
|
|
898
1199
|
excludePatterns,
|
|
1200
|
+
excludeFiles,
|
|
899
1201
|
confidenceThreshold,
|
|
900
1202
|
ignoreWhitelist,
|
|
901
1203
|
onProgress: options.onProgress
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
analyzePatterns,
|
|
3
3
|
generateSummary,
|
|
4
4
|
getSmartDefaults
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-WQC43BIO.mjs";
|
|
6
|
+
import "../chunk-XR373Q6G.mjs";
|
|
7
|
+
import "../chunk-XWIBTD67.mjs";
|
|
8
|
+
import "../chunk-UXV57HN3.mjs";
|
|
9
9
|
export {
|
|
10
10
|
analyzePatterns,
|
|
11
11
|
generateSummary,
|