@aiready/consistency 0.21.9 → 0.21.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 (132) hide show
  1. package/.turbo/turbo-build.log +23 -24
  2. package/dist/index.d.mts +3 -3
  3. package/dist/index.d.ts +3 -3
  4. package/dist/index.js +4 -4
  5. package/dist/index.mjs +3 -3
  6. package/package.json +2 -2
  7. package/src/__tests__/provider.test.ts +6 -34
  8. package/src/index.ts +3 -3
  9. package/src/provider.ts +2 -2
  10. package/dist/__tests__/analyzer.test.d.ts +0 -2
  11. package/dist/__tests__/analyzer.test.d.ts.map +0 -1
  12. package/dist/__tests__/analyzer.test.js +0 -157
  13. package/dist/__tests__/analyzer.test.js.map +0 -1
  14. package/dist/__tests__/language-filter.test.d.ts +0 -2
  15. package/dist/__tests__/language-filter.test.d.ts.map +0 -1
  16. package/dist/__tests__/language-filter.test.js +0 -46
  17. package/dist/__tests__/language-filter.test.js.map +0 -1
  18. package/dist/__tests__/scoring.test.d.ts +0 -2
  19. package/dist/__tests__/scoring.test.d.ts.map +0 -1
  20. package/dist/__tests__/scoring.test.js +0 -118
  21. package/dist/__tests__/scoring.test.js.map +0 -1
  22. package/dist/analyzer.d.ts +0 -7
  23. package/dist/analyzer.d.ts.map +0 -1
  24. package/dist/analyzer.js +0 -160
  25. package/dist/analyzer.js.map +0 -1
  26. package/dist/analyzers/naming-ast.d.ts +0 -7
  27. package/dist/analyzers/naming-ast.d.ts.map +0 -1
  28. package/dist/analyzers/naming-ast.js +0 -253
  29. package/dist/analyzers/naming-ast.js.map +0 -1
  30. package/dist/analyzers/naming-constants.d.ts +0 -21
  31. package/dist/analyzers/naming-constants.d.ts.map +0 -1
  32. package/dist/analyzers/naming-constants.js +0 -96
  33. package/dist/analyzers/naming-constants.js.map +0 -1
  34. package/dist/analyzers/naming-python.d.ts +0 -16
  35. package/dist/analyzers/naming-python.d.ts.map +0 -1
  36. package/dist/analyzers/naming-python.js +0 -165
  37. package/dist/analyzers/naming-python.js.map +0 -1
  38. package/dist/analyzers/naming.d.ts +0 -6
  39. package/dist/analyzers/naming.d.ts.map +0 -1
  40. package/dist/analyzers/naming.js +0 -234
  41. package/dist/analyzers/naming.js.map +0 -1
  42. package/dist/analyzers/patterns.d.ts +0 -10
  43. package/dist/analyzers/patterns.d.ts.map +0 -1
  44. package/dist/analyzers/patterns.js +0 -197
  45. package/dist/analyzers/patterns.js.map +0 -1
  46. package/dist/chunk-2BTBNG6X.mjs +0 -814
  47. package/dist/chunk-3ZB6FFRL.mjs +0 -661
  48. package/dist/chunk-5UFRGXSB.mjs +0 -783
  49. package/dist/chunk-66M3TIO7.mjs +0 -837
  50. package/dist/chunk-6BM5MV3S.mjs +0 -719
  51. package/dist/chunk-6H3JHDP7.mjs +0 -832
  52. package/dist/chunk-7PHHJOGC.mjs +0 -1374
  53. package/dist/chunk-AASFXGUR.mjs +0 -1622
  54. package/dist/chunk-AR7DIZLP.mjs +0 -827
  55. package/dist/chunk-BDDMOIU2.mjs +0 -385
  56. package/dist/chunk-BMILMNKJ.mjs +0 -1633
  57. package/dist/chunk-BYY6MD5T.mjs +0 -729
  58. package/dist/chunk-CA4Q5JBK.mjs +0 -1143
  59. package/dist/chunk-CF4LU7KE.mjs +0 -384
  60. package/dist/chunk-CJINEUIH.mjs +0 -1369
  61. package/dist/chunk-CLWNLHDB.mjs +0 -909
  62. package/dist/chunk-CZUJTDNH.mjs +0 -848
  63. package/dist/chunk-DNGW3WQK.mjs +0 -810
  64. package/dist/chunk-DSI3TEO2.mjs +0 -662
  65. package/dist/chunk-EIQ5K6OO.mjs +0 -1579
  66. package/dist/chunk-FEJODRK5.mjs +0 -783
  67. package/dist/chunk-FK56AZ43.mjs +0 -817
  68. package/dist/chunk-H6S7WKSQ.mjs +0 -729
  69. package/dist/chunk-HAOJLJNB.mjs +0 -1290
  70. package/dist/chunk-HJCP36VW.mjs +0 -821
  71. package/dist/chunk-HPG7P6PD.mjs +0 -1372
  72. package/dist/chunk-IVRBV7SE.mjs +0 -1295
  73. package/dist/chunk-IXBC6GVT.mjs +0 -832
  74. package/dist/chunk-J5IFYDVU.mjs +0 -1579
  75. package/dist/chunk-KWQVBF7K.mjs +0 -831
  76. package/dist/chunk-LD3CHHU2.mjs +0 -1297
  77. package/dist/chunk-LMOXGPCM.mjs +0 -722
  78. package/dist/chunk-LSXZH6X6.mjs +0 -810
  79. package/dist/chunk-LUAREV6A.mjs +0 -508
  80. package/dist/chunk-MAPVFXBP.mjs +0 -708
  81. package/dist/chunk-MM2PLUCH.mjs +0 -1376
  82. package/dist/chunk-NPWCJZUG.mjs +0 -708
  83. package/dist/chunk-ON73WHHU.mjs +0 -1310
  84. package/dist/chunk-P6NVKUBB.mjs +0 -831
  85. package/dist/chunk-Q3KTWDSL.mjs +0 -808
  86. package/dist/chunk-Q5XMWG33.mjs +0 -661
  87. package/dist/chunk-QOIPVP6P.mjs +0 -1607
  88. package/dist/chunk-RMEQWG52.mjs +0 -1633
  89. package/dist/chunk-S6BZVTWN.mjs +0 -731
  90. package/dist/chunk-TE6JYZD3.mjs +0 -810
  91. package/dist/chunk-TLVLM3M5.mjs +0 -771
  92. package/dist/chunk-TXHPUU7A.mjs +0 -863
  93. package/dist/chunk-UMBBTNQN.mjs +0 -787
  94. package/dist/chunk-V2UPXL7L.mjs +0 -842
  95. package/dist/chunk-VODCPPET.mjs +0 -1292
  96. package/dist/chunk-W6UGMKRV.mjs +0 -1310
  97. package/dist/chunk-WGH4TGZ3.mjs +0 -1288
  98. package/dist/chunk-WTBDNCEN.mjs +0 -1352
  99. package/dist/chunk-XVW5DKJQ.mjs +0 -1619
  100. package/dist/chunk-YCDCIOJN.mjs +0 -842
  101. package/dist/chunk-YEHXYHGY.mjs +0 -1497
  102. package/dist/chunk-YHHXE2JX.mjs +0 -912
  103. package/dist/chunk-ZB6UK276.mjs +0 -662
  104. package/dist/chunk-ZG3KFSD3.mjs +0 -1142
  105. package/dist/cli.d.ts.map +0 -1
  106. package/dist/cli.js.map +0 -1
  107. package/dist/index.d.ts.map +0 -1
  108. package/dist/index.js.map +0 -1
  109. package/dist/scoring.d.ts +0 -12
  110. package/dist/scoring.d.ts.map +0 -1
  111. package/dist/scoring.js +0 -110
  112. package/dist/scoring.js.map +0 -1
  113. package/dist/types.d.ts +0 -53
  114. package/dist/types.d.ts.map +0 -1
  115. package/dist/types.js +0 -2
  116. package/dist/types.js.map +0 -1
  117. package/dist/utils/ast-parser.d.ts +0 -46
  118. package/dist/utils/ast-parser.d.ts.map +0 -1
  119. package/dist/utils/ast-parser.js +0 -157
  120. package/dist/utils/ast-parser.js.map +0 -1
  121. package/dist/utils/config-loader.d.ts +0 -19
  122. package/dist/utils/config-loader.d.ts.map +0 -1
  123. package/dist/utils/config-loader.js +0 -31
  124. package/dist/utils/config-loader.js.map +0 -1
  125. package/dist/utils/context-detector.d.ts +0 -40
  126. package/dist/utils/context-detector.d.ts.map +0 -1
  127. package/dist/utils/context-detector.js +0 -225
  128. package/dist/utils/context-detector.js.map +0 -1
  129. package/dist/utils/scope-tracker.d.ts +0 -87
  130. package/dist/utils/scope-tracker.d.ts.map +0 -1
  131. package/dist/utils/scope-tracker.js +0 -161
  132. package/dist/utils/scope-tracker.js.map +0 -1
@@ -1,384 +0,0 @@
1
- // src/analyzers/naming.ts
2
- import { readFileContent } from "@aiready/core";
3
- async function analyzeNaming(files) {
4
- const issues = [];
5
- for (const file of files) {
6
- const content = await readFileContent(file);
7
- const fileIssues = analyzeFileNaming(file, content);
8
- issues.push(...fileIssues);
9
- }
10
- return issues;
11
- }
12
- function analyzeFileNaming(file, content) {
13
- const issues = [];
14
- const lines = content.split("\n");
15
- lines.forEach((line, index) => {
16
- const lineNumber = index + 1;
17
- const singleLetterMatches = line.matchAll(/\b(?:const|let|var)\s+([a-hm-z])\s*=/gi);
18
- for (const match of singleLetterMatches) {
19
- issues.push({
20
- file,
21
- line: lineNumber,
22
- type: "poor-naming",
23
- identifier: match[1],
24
- severity: "minor",
25
- suggestion: `Use descriptive variable name instead of single letter '${match[1]}'`
26
- });
27
- }
28
- const abbreviationMatches = line.matchAll(/\b(?:const|let|var)\s+([a-z]{1,3})(?=[A-Z]|_|\s*=)/g);
29
- for (const match of abbreviationMatches) {
30
- const abbrev = match[1];
31
- if (!["id", "url", "api", "db", "fs", "os", "ui"].includes(abbrev.toLowerCase())) {
32
- issues.push({
33
- file,
34
- line: lineNumber,
35
- type: "abbreviation",
36
- identifier: abbrev,
37
- severity: "info",
38
- suggestion: `Consider using full word instead of abbreviation '${abbrev}'`
39
- });
40
- }
41
- }
42
- if (file.match(/\.(ts|tsx|js|jsx)$/)) {
43
- const camelCaseVars = line.match(/\b(?:const|let|var)\s+([a-z][a-zA-Z0-9]*)\s*=/);
44
- const snakeCaseVars = line.match(/\b(?:const|let|var)\s+([a-z][a-z0-9]*_[a-z0-9_]*)\s*=/);
45
- if (snakeCaseVars) {
46
- issues.push({
47
- file,
48
- line: lineNumber,
49
- type: "convention-mix",
50
- identifier: snakeCaseVars[1],
51
- severity: "minor",
52
- suggestion: `Use camelCase '${snakeCaseToCamelCase(snakeCaseVars[1])}' instead of snake_case in TypeScript/JavaScript`
53
- });
54
- }
55
- }
56
- const booleanMatches = line.matchAll(/\b(?:const|let|var)\s+([a-z][a-zA-Z0-9]*)\s*:\s*boolean/gi);
57
- for (const match of booleanMatches) {
58
- const name = match[1];
59
- if (!name.match(/^(is|has|should|can|will|did)/i)) {
60
- issues.push({
61
- file,
62
- line: lineNumber,
63
- type: "unclear",
64
- identifier: name,
65
- severity: "info",
66
- suggestion: `Boolean variable '${name}' should start with is/has/should/can for clarity`
67
- });
68
- }
69
- }
70
- const functionMatches = line.matchAll(/function\s+([a-z][a-zA-Z0-9]*)/g);
71
- for (const match of functionMatches) {
72
- const name = match[1];
73
- if (!name.match(/^(get|set|is|has|can|should|create|update|delete|fetch|load|save|process|handle|validate|check|find|search|filter|map|reduce)/)) {
74
- issues.push({
75
- file,
76
- line: lineNumber,
77
- type: "unclear",
78
- identifier: name,
79
- severity: "info",
80
- suggestion: `Function '${name}' should start with an action verb (get, set, create, etc.)`
81
- });
82
- }
83
- }
84
- });
85
- return issues;
86
- }
87
- function snakeCaseToCamelCase(str) {
88
- return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
89
- }
90
- function detectNamingConventions(files, allIssues) {
91
- const camelCaseCount = allIssues.filter((i) => i.type === "convention-mix").length;
92
- const totalChecks = files.length * 10;
93
- if (camelCaseCount / totalChecks > 0.3) {
94
- return { dominantConvention: "mixed", conventionScore: 0.5 };
95
- }
96
- return { dominantConvention: "camelCase", conventionScore: 0.9 };
97
- }
98
-
99
- // src/analyzers/patterns.ts
100
- import { readFileContent as readFileContent2 } from "@aiready/core";
101
- async function analyzePatterns(files) {
102
- const issues = [];
103
- const errorHandlingIssues = await analyzeErrorHandling(files);
104
- issues.push(...errorHandlingIssues);
105
- const asyncIssues = await analyzeAsyncPatterns(files);
106
- issues.push(...asyncIssues);
107
- const importIssues = await analyzeImportStyles(files);
108
- issues.push(...importIssues);
109
- return issues;
110
- }
111
- async function analyzeErrorHandling(files) {
112
- const patterns = {
113
- tryCatch: [],
114
- throwsError: [],
115
- returnsNull: [],
116
- returnsError: []
117
- };
118
- for (const file of files) {
119
- const content = await readFileContent2(file);
120
- if (content.includes("try {") || content.includes("} catch")) {
121
- patterns.tryCatch.push(file);
122
- }
123
- if (content.match(/throw new \w*Error/)) {
124
- patterns.throwsError.push(file);
125
- }
126
- if (content.match(/return null/)) {
127
- patterns.returnsNull.push(file);
128
- }
129
- if (content.match(/return \{ error:/)) {
130
- patterns.returnsError.push(file);
131
- }
132
- }
133
- const issues = [];
134
- const strategiesUsed = Object.values(patterns).filter((p) => p.length > 0).length;
135
- if (strategiesUsed > 2) {
136
- issues.push({
137
- files: [.../* @__PURE__ */ new Set([
138
- ...patterns.tryCatch,
139
- ...patterns.throwsError,
140
- ...patterns.returnsNull,
141
- ...patterns.returnsError
142
- ])],
143
- type: "error-handling",
144
- description: "Inconsistent error handling strategies across codebase",
145
- examples: [
146
- patterns.tryCatch.length > 0 ? `Try-catch used in ${patterns.tryCatch.length} files` : "",
147
- patterns.throwsError.length > 0 ? `Throws errors in ${patterns.throwsError.length} files` : "",
148
- patterns.returnsNull.length > 0 ? `Returns null in ${patterns.returnsNull.length} files` : "",
149
- patterns.returnsError.length > 0 ? `Returns error objects in ${patterns.returnsError.length} files` : ""
150
- ].filter((e) => e),
151
- severity: "major"
152
- });
153
- }
154
- return issues;
155
- }
156
- async function analyzeAsyncPatterns(files) {
157
- const patterns = {
158
- asyncAwait: [],
159
- promises: [],
160
- callbacks: []
161
- };
162
- for (const file of files) {
163
- const content = await readFileContent2(file);
164
- if (content.match(/async\s+(function|\(|[a-zA-Z])/)) {
165
- patterns.asyncAwait.push(file);
166
- }
167
- if (content.match(/\.then\(/) || content.match(/\.catch\(/)) {
168
- patterns.promises.push(file);
169
- }
170
- if (content.match(/callback\s*\(/) || content.match(/\(\s*err\s*,/)) {
171
- patterns.callbacks.push(file);
172
- }
173
- }
174
- const issues = [];
175
- if (patterns.callbacks.length > 0 && patterns.asyncAwait.length > 0) {
176
- issues.push({
177
- files: [...patterns.callbacks, ...patterns.asyncAwait],
178
- type: "async-style",
179
- description: "Mixed async patterns: callbacks and async/await",
180
- examples: [
181
- `Callbacks found in: ${patterns.callbacks.slice(0, 3).join(", ")}`,
182
- `Async/await used in: ${patterns.asyncAwait.slice(0, 3).join(", ")}`
183
- ],
184
- severity: "minor"
185
- });
186
- }
187
- if (patterns.promises.length > patterns.asyncAwait.length * 0.3 && patterns.asyncAwait.length > 0) {
188
- issues.push({
189
- files: patterns.promises,
190
- type: "async-style",
191
- description: "Consider using async/await instead of promise chains for consistency",
192
- examples: patterns.promises.slice(0, 5),
193
- severity: "info"
194
- });
195
- }
196
- return issues;
197
- }
198
- async function analyzeImportStyles(files) {
199
- const patterns = {
200
- esModules: [],
201
- commonJS: [],
202
- mixed: []
203
- };
204
- for (const file of files) {
205
- const content = await readFileContent2(file);
206
- const hasESM = content.match(/^import\s+/m);
207
- const hasCJS = content.match(/require\s*\(/);
208
- if (hasESM && hasCJS) {
209
- patterns.mixed.push(file);
210
- } else if (hasESM) {
211
- patterns.esModules.push(file);
212
- } else if (hasCJS) {
213
- patterns.commonJS.push(file);
214
- }
215
- }
216
- const issues = [];
217
- if (patterns.mixed.length > 0) {
218
- issues.push({
219
- files: patterns.mixed,
220
- type: "import-style",
221
- description: "Mixed ES modules and CommonJS imports in same files",
222
- examples: patterns.mixed.slice(0, 5),
223
- severity: "major"
224
- });
225
- }
226
- if (patterns.esModules.length > 0 && patterns.commonJS.length > 0) {
227
- const ratio = patterns.commonJS.length / (patterns.esModules.length + patterns.commonJS.length);
228
- if (ratio > 0.2 && ratio < 0.8) {
229
- issues.push({
230
- files: [...patterns.esModules, ...patterns.commonJS],
231
- type: "import-style",
232
- description: "Inconsistent import styles across project",
233
- examples: [
234
- `ES modules: ${patterns.esModules.length} files`,
235
- `CommonJS: ${patterns.commonJS.length} files`
236
- ],
237
- severity: "minor"
238
- });
239
- }
240
- }
241
- return issues;
242
- }
243
-
244
- // src/analyzer.ts
245
- import { scanFiles } from "@aiready/core";
246
- async function analyzeConsistency(options) {
247
- const {
248
- checkNaming = true,
249
- checkPatterns = true,
250
- checkArchitecture = false,
251
- // Not implemented yet
252
- minSeverity = "info",
253
- ...scanOptions
254
- } = options;
255
- const filePaths = await scanFiles(scanOptions);
256
- const namingIssues = checkNaming ? await analyzeNaming(filePaths) : [];
257
- const patternIssues = checkPatterns ? await analyzePatterns(filePaths) : [];
258
- const results = [];
259
- const fileIssuesMap = /* @__PURE__ */ new Map();
260
- for (const issue of namingIssues) {
261
- if (!shouldIncludeSeverity(issue.severity, minSeverity)) {
262
- continue;
263
- }
264
- const consistencyIssue = {
265
- type: issue.type === "convention-mix" ? "naming-inconsistency" : "naming-quality",
266
- category: "naming",
267
- severity: issue.severity,
268
- message: `${issue.type}: ${issue.identifier}`,
269
- location: {
270
- file: issue.file,
271
- line: issue.line,
272
- column: issue.column
273
- },
274
- suggestion: issue.suggestion
275
- };
276
- if (!fileIssuesMap.has(issue.file)) {
277
- fileIssuesMap.set(issue.file, []);
278
- }
279
- fileIssuesMap.get(issue.file).push(consistencyIssue);
280
- }
281
- for (const issue of patternIssues) {
282
- if (!shouldIncludeSeverity(issue.severity, minSeverity)) {
283
- continue;
284
- }
285
- const consistencyIssue = {
286
- type: "pattern-inconsistency",
287
- category: "patterns",
288
- severity: issue.severity,
289
- message: issue.description,
290
- location: {
291
- file: issue.files[0] || "multiple files",
292
- line: 1
293
- },
294
- examples: issue.examples,
295
- suggestion: `Standardize ${issue.type} patterns across ${issue.files.length} files`
296
- };
297
- const firstFile = issue.files[0];
298
- if (firstFile && !fileIssuesMap.has(firstFile)) {
299
- fileIssuesMap.set(firstFile, []);
300
- }
301
- if (firstFile) {
302
- fileIssuesMap.get(firstFile).push(consistencyIssue);
303
- }
304
- }
305
- for (const [fileName, issues] of fileIssuesMap) {
306
- results.push({
307
- fileName,
308
- issues,
309
- metrics: {
310
- consistencyScore: calculateConsistencyScore(issues)
311
- }
312
- });
313
- }
314
- const recommendations = generateRecommendations(namingIssues, patternIssues);
315
- const conventionAnalysis = detectNamingConventions(filePaths, namingIssues);
316
- return {
317
- summary: {
318
- totalIssues: namingIssues.length + patternIssues.length,
319
- namingIssues: namingIssues.length,
320
- patternIssues: patternIssues.length,
321
- architectureIssues: 0,
322
- filesAnalyzed: filePaths.length
323
- },
324
- results,
325
- recommendations
326
- };
327
- }
328
- function shouldIncludeSeverity(severity, minSeverity) {
329
- const severityLevels = { info: 0, minor: 1, major: 2, critical: 3 };
330
- return severityLevels[severity] >= severityLevels[minSeverity];
331
- }
332
- function calculateConsistencyScore(issues) {
333
- const weights = { critical: 10, major: 5, minor: 2, info: 1 };
334
- const totalWeight = issues.reduce((sum, issue) => sum + weights[issue.severity], 0);
335
- return Math.max(0, 1 - totalWeight / 100);
336
- }
337
- function generateRecommendations(namingIssues, patternIssues) {
338
- const recommendations = [];
339
- if (namingIssues.length > 0) {
340
- const conventionMixCount = namingIssues.filter((i) => i.type === "convention-mix").length;
341
- if (conventionMixCount > 0) {
342
- recommendations.push(
343
- `Standardize naming conventions: Found ${conventionMixCount} snake_case variables in TypeScript/JavaScript (use camelCase)`
344
- );
345
- }
346
- const poorNamingCount = namingIssues.filter((i) => i.type === "poor-naming").length;
347
- if (poorNamingCount > 0) {
348
- recommendations.push(
349
- `Improve variable naming: Found ${poorNamingCount} single-letter or unclear variable names`
350
- );
351
- }
352
- }
353
- if (patternIssues.length > 0) {
354
- const errorHandlingIssues = patternIssues.filter((i) => i.type === "error-handling");
355
- if (errorHandlingIssues.length > 0) {
356
- recommendations.push(
357
- "Standardize error handling strategy across the codebase (prefer try-catch with typed errors)"
358
- );
359
- }
360
- const asyncIssues = patternIssues.filter((i) => i.type === "async-style");
361
- if (asyncIssues.length > 0) {
362
- recommendations.push(
363
- "Use async/await consistently instead of mixing with promise chains or callbacks"
364
- );
365
- }
366
- const importIssues = patternIssues.filter((i) => i.type === "import-style");
367
- if (importIssues.length > 0) {
368
- recommendations.push(
369
- "Use ES modules consistently across the project (avoid mixing with CommonJS)"
370
- );
371
- }
372
- }
373
- if (recommendations.length === 0) {
374
- recommendations.push("No major consistency issues found! Your codebase follows good practices.");
375
- }
376
- return recommendations;
377
- }
378
-
379
- export {
380
- analyzeNaming,
381
- detectNamingConventions,
382
- analyzePatterns,
383
- analyzeConsistency
384
- };