@aiready/consistency 0.6.4 → 0.6.6

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/index.mjs CHANGED
@@ -1,394 +1,16 @@
1
1
  import {
2
+ ACCEPTABLE_ABBREVIATIONS,
3
+ COMMON_SHORT_WORDS,
2
4
  analyzeConsistency,
3
5
  analyzeNamingAST,
4
- analyzePatterns
5
- } from "./chunk-ON73WHHU.mjs";
6
+ analyzePatterns,
7
+ detectNamingConventions,
8
+ snakeCaseToCamelCase
9
+ } from "./chunk-WTBDNCEN.mjs";
6
10
 
7
11
  // src/analyzers/naming.ts
8
12
  import { readFileContent, loadConfig } from "@aiready/core";
9
13
  import { dirname } from "path";
10
- var COMMON_SHORT_WORDS = /* @__PURE__ */ new Set([
11
- // Full English words (1-3 letters)
12
- "day",
13
- "key",
14
- "net",
15
- "to",
16
- "go",
17
- "for",
18
- "not",
19
- "new",
20
- "old",
21
- "top",
22
- "end",
23
- "run",
24
- "try",
25
- "use",
26
- "get",
27
- "set",
28
- "add",
29
- "put",
30
- "map",
31
- "log",
32
- "row",
33
- "col",
34
- "tab",
35
- "box",
36
- "div",
37
- "nav",
38
- "tag",
39
- "any",
40
- "all",
41
- "one",
42
- "two",
43
- "out",
44
- "off",
45
- "on",
46
- "yes",
47
- "no",
48
- "now",
49
- "max",
50
- "min",
51
- "sum",
52
- "avg",
53
- "ref",
54
- "src",
55
- "dst",
56
- "raw",
57
- "def",
58
- "sub",
59
- "pub",
60
- "pre",
61
- "mid",
62
- "alt",
63
- "opt",
64
- "tmp",
65
- "ext",
66
- "sep",
67
- // Prepositions and conjunctions
68
- "and",
69
- "from",
70
- "how",
71
- "pad",
72
- "bar",
73
- "non",
74
- // Additional full words commonly flagged
75
- "tax",
76
- "cat",
77
- "dog",
78
- "car",
79
- "bus",
80
- "web",
81
- "app",
82
- "war",
83
- "law",
84
- "pay",
85
- "buy",
86
- "win",
87
- "cut",
88
- "hit",
89
- "hot",
90
- "pop",
91
- "job",
92
- "age",
93
- "act",
94
- "let",
95
- "lot",
96
- "bad",
97
- "big",
98
- "far",
99
- "few",
100
- "own",
101
- "per",
102
- "red",
103
- "low",
104
- "see",
105
- "six",
106
- "ten",
107
- "way",
108
- "who",
109
- "why",
110
- "yet",
111
- "via",
112
- "due",
113
- "fee",
114
- "fun",
115
- "gas",
116
- "gay",
117
- "god",
118
- "gun",
119
- "guy",
120
- "ice",
121
- "ill",
122
- "kid",
123
- "mad",
124
- "man",
125
- "mix",
126
- "mom",
127
- "mrs",
128
- "nor",
129
- "odd",
130
- "oil",
131
- "pan",
132
- "pet",
133
- "pit",
134
- "pot",
135
- "pow",
136
- "pro",
137
- "raw",
138
- "rep",
139
- "rid",
140
- "sad",
141
- "sea",
142
- "sit",
143
- "sky",
144
- "son",
145
- "tea",
146
- "tie",
147
- "tip",
148
- "van",
149
- "war",
150
- "win",
151
- "won"
152
- ]);
153
- var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
154
- // Standard identifiers
155
- "id",
156
- "uid",
157
- "gid",
158
- "pid",
159
- // Loop counters and iterators
160
- "i",
161
- "j",
162
- "k",
163
- "n",
164
- "m",
165
- // Web/Network
166
- "url",
167
- "uri",
168
- "api",
169
- "cdn",
170
- "dns",
171
- "ip",
172
- "tcp",
173
- "udp",
174
- "http",
175
- "ssl",
176
- "tls",
177
- "utm",
178
- "seo",
179
- "rss",
180
- "xhr",
181
- "ajax",
182
- "cors",
183
- "ws",
184
- "wss",
185
- // Data formats
186
- "json",
187
- "xml",
188
- "yaml",
189
- "csv",
190
- "html",
191
- "css",
192
- "svg",
193
- "pdf",
194
- // File types & extensions
195
- "img",
196
- "txt",
197
- "doc",
198
- "docx",
199
- "xlsx",
200
- "ppt",
201
- "md",
202
- "rst",
203
- "jpg",
204
- "png",
205
- "gif",
206
- // Databases
207
- "db",
208
- "sql",
209
- "orm",
210
- "dao",
211
- "dto",
212
- "ddb",
213
- "rds",
214
- "nosql",
215
- // File system
216
- "fs",
217
- "dir",
218
- "tmp",
219
- "src",
220
- "dst",
221
- "bin",
222
- "lib",
223
- "pkg",
224
- // Operating system
225
- "os",
226
- "env",
227
- "arg",
228
- "cli",
229
- "cmd",
230
- "exe",
231
- "cwd",
232
- "pwd",
233
- // UI/UX
234
- "ui",
235
- "ux",
236
- "gui",
237
- "dom",
238
- "ref",
239
- // Request/Response
240
- "req",
241
- "res",
242
- "ctx",
243
- "err",
244
- "msg",
245
- "auth",
246
- // Mathematics/Computing
247
- "max",
248
- "min",
249
- "avg",
250
- "sum",
251
- "abs",
252
- "cos",
253
- "sin",
254
- "tan",
255
- "log",
256
- "exp",
257
- "pow",
258
- "sqrt",
259
- "std",
260
- "var",
261
- "int",
262
- "num",
263
- "idx",
264
- // Time
265
- "now",
266
- "utc",
267
- "tz",
268
- "ms",
269
- "sec",
270
- "hr",
271
- "min",
272
- "yr",
273
- "mo",
274
- // Common patterns
275
- "app",
276
- "cfg",
277
- "config",
278
- "init",
279
- "len",
280
- "val",
281
- "str",
282
- "obj",
283
- "arr",
284
- "gen",
285
- "def",
286
- "raw",
287
- "new",
288
- "old",
289
- "pre",
290
- "post",
291
- "sub",
292
- "pub",
293
- // Programming/Framework specific
294
- "ts",
295
- "js",
296
- "jsx",
297
- "tsx",
298
- "py",
299
- "rb",
300
- "vue",
301
- "re",
302
- "fn",
303
- "fns",
304
- "mod",
305
- "opts",
306
- "dev",
307
- // Cloud/Infrastructure
308
- "s3",
309
- "ec2",
310
- "sqs",
311
- "sns",
312
- "vpc",
313
- "ami",
314
- "iam",
315
- "acl",
316
- "elb",
317
- "alb",
318
- "nlb",
319
- "aws",
320
- "ses",
321
- "gst",
322
- "cdk",
323
- "btn",
324
- "buf",
325
- "agg",
326
- "ocr",
327
- "ai",
328
- "cf",
329
- "cfn",
330
- "ga",
331
- // Metrics/Performance
332
- "fcp",
333
- "lcp",
334
- "cls",
335
- "ttfb",
336
- "tti",
337
- "fid",
338
- "fps",
339
- "qps",
340
- "rps",
341
- "tps",
342
- "wpm",
343
- // Testing & i18n
344
- "po",
345
- "e2e",
346
- "a11y",
347
- "i18n",
348
- "l10n",
349
- "spy",
350
- // Domain-specific abbreviations (context-aware)
351
- "sk",
352
- "fy",
353
- "faq",
354
- "og",
355
- "seo",
356
- "cta",
357
- "roi",
358
- "kpi",
359
- "ttl",
360
- "pct",
361
- // Technical abbreviations
362
- "mac",
363
- "hex",
364
- "esm",
365
- "git",
366
- "rec",
367
- "loc",
368
- "dup",
369
- // Boolean helpers (these are intentional short names)
370
- "is",
371
- "has",
372
- "can",
373
- "did",
374
- "was",
375
- "are",
376
- // Date/Time context (when in date contexts)
377
- "d",
378
- "t",
379
- "dt",
380
- // Coverage metrics (industry standard: statements/branches/functions/lines)
381
- "s",
382
- "b",
383
- "f",
384
- "l",
385
- // Common media/content abbreviations
386
- "vid",
387
- "pic",
388
- "img",
389
- "doc",
390
- "msg"
391
- ]);
392
14
  async function analyzeNaming(files) {
393
15
  const issues = [];
394
16
  const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
@@ -569,17 +191,6 @@ function analyzeFileNaming(file, content, customAbbreviations, customShortWords,
569
191
  });
570
192
  return issues;
571
193
  }
572
- function snakeCaseToCamelCase(str) {
573
- return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
574
- }
575
- function detectNamingConventions(files, allIssues) {
576
- const camelCaseCount = allIssues.filter((i) => i.type === "convention-mix").length;
577
- const totalChecks = files.length * 10;
578
- if (camelCaseCount / totalChecks > 0.3) {
579
- return { dominantConvention: "mixed", conventionScore: 0.5 };
580
- }
581
- return { dominantConvention: "camelCase", conventionScore: 0.9 };
582
- }
583
194
  export {
584
195
  analyzeConsistency,
585
196
  analyzeNaming,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/consistency",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Detects consistency issues in naming, patterns, and architecture that confuse AI models",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -43,7 +43,7 @@
43
43
  "@typescript-eslint/typescript-estree": "^8.53.0",
44
44
  "chalk": "^5.3.0",
45
45
  "commander": "^12.1.0",
46
- "@aiready/core": "0.7.3"
46
+ "@aiready/core": "0.7.4"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^22.10.5",
@@ -18,53 +18,10 @@ import {
18
18
  isAcceptableInContext,
19
19
  calculateComplexity,
20
20
  } from '../utils/context-detector';
21
-
22
- // Common short English words that are NOT abbreviations (full, valid words)
23
- const COMMON_SHORT_WORDS = new Set([
24
- 'day', 'key', 'net', 'to', 'go', 'for', 'not', 'new', 'old', 'top', 'end',
25
- 'run', 'try', 'use', 'get', 'set', 'add', 'put', 'map', 'log', 'row', 'col',
26
- 'tab', 'box', 'div', 'nav', 'tag', 'any', 'all', 'one', 'two', 'out', 'off',
27
- 'on', 'yes', 'no', 'now', 'max', 'min', 'sum', 'avg', 'ref', 'src', 'dst',
28
- 'raw', 'def', 'sub', 'pub', 'pre', 'mid', 'alt', 'opt', 'tmp', 'ext', 'sep',
29
- 'and', 'from', 'how', 'pad', 'bar', 'non',
30
- 'tax', 'cat', 'dog', 'car', 'bus', 'web', 'app', 'war', 'law', 'pay', 'buy',
31
- 'win', 'cut', 'hit', 'hot', 'pop', 'job', 'age', 'act', 'let', 'lot', 'bad',
32
- 'big', 'far', 'few', 'own', 'per', 'red', 'low', 'see', 'six', 'ten', 'way',
33
- 'who', 'why', 'yet', 'via', 'due', 'fee', 'fun', 'gas', 'gay', 'god', 'gun',
34
- 'guy', 'ice', 'ill', 'kid', 'mad', 'man', 'mix', 'mom', 'mrs', 'nor', 'odd',
35
- 'oil', 'pan', 'pet', 'pit', 'pot', 'pow', 'pro', 'raw', 'rep', 'rid', 'sad',
36
- 'sea', 'sit', 'sky', 'son', 'tea', 'tie', 'tip', 'van', 'war', 'win', 'won'
37
- ]);
38
-
39
- // Comprehensive list of acceptable abbreviations and acronyms
40
- const ACCEPTABLE_ABBREVIATIONS = new Set([
41
- 'id', 'uid', 'gid', 'pid', 'i', 'j', 'k', 'n', 'm',
42
- 'url', 'uri', 'api', 'cdn', 'dns', 'ip', 'tcp', 'udp', 'http', 'ssl', 'tls',
43
- 'utm', 'seo', 'rss', 'xhr', 'ajax', 'cors', 'ws', 'wss',
44
- 'json', 'xml', 'yaml', 'csv', 'html', 'css', 'svg', 'pdf',
45
- 'img', 'txt', 'doc', 'docx', 'xlsx', 'ppt', 'md', 'rst', 'jpg', 'png', 'gif',
46
- 'db', 'sql', 'orm', 'dao', 'dto', 'ddb', 'rds', 'nosql',
47
- 'fs', 'dir', 'tmp', 'src', 'dst', 'bin', 'lib', 'pkg',
48
- 'os', 'env', 'arg', 'cli', 'cmd', 'exe', 'cwd', 'pwd',
49
- 'ui', 'ux', 'gui', 'dom', 'ref',
50
- 'req', 'res', 'ctx', 'err', 'msg', 'auth',
51
- 'max', 'min', 'avg', 'sum', 'abs', 'cos', 'sin', 'tan', 'log', 'exp',
52
- 'pow', 'sqrt', 'std', 'var', 'int', 'num', 'idx',
53
- 'now', 'utc', 'tz', 'ms', 'sec', 'hr', 'min', 'yr', 'mo',
54
- 'app', 'cfg', 'config', 'init', 'len', 'val', 'str', 'obj', 'arr',
55
- 'gen', 'def', 'raw', 'new', 'old', 'pre', 'post', 'sub', 'pub',
56
- 'ts', 'js', 'jsx', 'tsx', 'py', 'rb', 'vue', 're', 'fn', 'fns', 'mod', 'opts', 'dev',
57
- 's3', 'ec2', 'sqs', 'sns', 'vpc', 'ami', 'iam', 'acl', 'elb', 'alb', 'nlb', 'aws',
58
- 'ses', 'gst', 'cdk', 'btn', 'buf', 'agg', 'ocr', 'ai', 'cf', 'cfn', 'ga',
59
- 'fcp', 'lcp', 'cls', 'ttfb', 'tti', 'fid', 'fps', 'qps', 'rps', 'tps', 'wpm',
60
- 'po', 'e2e', 'a11y', 'i18n', 'l10n', 'spy',
61
- 'sk', 'fy', 'faq', 'og', 'seo', 'cta', 'roi', 'kpi', 'ttl', 'pct',
62
- 'mac', 'hex', 'esm', 'git', 'rec', 'loc', 'dup',
63
- 'is', 'has', 'can', 'did', 'was', 'are',
64
- 'd', 't', 'dt',
65
- 's', 'b', 'f', 'l', // Coverage metrics
66
- 'vid', 'pic', 'img', 'doc', 'msg'
67
- ]);
21
+ import {
22
+ COMMON_SHORT_WORDS,
23
+ ACCEPTABLE_ABBREVIATIONS,
24
+ } from './naming-constants';
68
25
 
69
26
  /**
70
27
  * AST-based naming analyzer
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Shared constants and utilities for naming analysis
3
+ * Extracted from naming.ts and naming-ast.ts to reduce duplication
4
+ */
5
+
6
+ // Common short English words that are NOT abbreviations (full, valid words)
7
+ export const COMMON_SHORT_WORDS = new Set([
8
+ // Full English words (1-3 letters)
9
+ 'day', 'key', 'net', 'to', 'go', 'for', 'not', 'new', 'old', 'top', 'end',
10
+ 'run', 'try', 'use', 'get', 'set', 'add', 'put', 'map', 'log', 'row', 'col',
11
+ 'tab', 'box', 'div', 'nav', 'tag', 'any', 'all', 'one', 'two', 'out', 'off',
12
+ 'on', 'yes', 'no', 'now', 'max', 'min', 'sum', 'avg', 'ref', 'src', 'dst',
13
+ 'raw', 'def', 'sub', 'pub', 'pre', 'mid', 'alt', 'opt', 'tmp', 'ext', 'sep',
14
+ // Prepositions and conjunctions
15
+ 'and', 'from', 'how', 'pad', 'bar', 'non',
16
+ // Additional full words commonly flagged
17
+ 'tax', 'cat', 'dog', 'car', 'bus', 'web', 'app', 'war', 'law', 'pay', 'buy',
18
+ 'win', 'cut', 'hit', 'hot', 'pop', 'job', 'age', 'act', 'let', 'lot', 'bad',
19
+ 'big', 'far', 'few', 'own', 'per', 'red', 'low', 'see', 'six', 'ten', 'way',
20
+ 'who', 'why', 'yet', 'via', 'due', 'fee', 'fun', 'gas', 'gay', 'god', 'gun',
21
+ 'guy', 'ice', 'ill', 'kid', 'mad', 'man', 'mix', 'mom', 'mrs', 'nor', 'odd',
22
+ 'oil', 'pan', 'pet', 'pit', 'pot', 'pow', 'pro', 'raw', 'rep', 'rid', 'sad',
23
+ 'sea', 'sit', 'sky', 'son', 'tea', 'tie', 'tip', 'van', 'war', 'win', 'won'
24
+ ]);
25
+
26
+ // Comprehensive list of acceptable abbreviations and acronyms
27
+ export const ACCEPTABLE_ABBREVIATIONS = new Set([
28
+ // Standard identifiers
29
+ 'id', 'uid', 'gid', 'pid',
30
+ // Loop counters and iterators
31
+ 'i', 'j', 'k', 'n', 'm',
32
+ // Web/Network
33
+ 'url', 'uri', 'api', 'cdn', 'dns', 'ip', 'tcp', 'udp', 'http', 'ssl', 'tls',
34
+ 'utm', 'seo', 'rss', 'xhr', 'ajax', 'cors', 'ws', 'wss',
35
+ // Data formats
36
+ 'json', 'xml', 'yaml', 'csv', 'html', 'css', 'svg', 'pdf',
37
+ // File types & extensions
38
+ 'img', 'txt', 'doc', 'docx', 'xlsx', 'ppt', 'md', 'rst', 'jpg', 'png', 'gif',
39
+ // Databases
40
+ 'db', 'sql', 'orm', 'dao', 'dto', 'ddb', 'rds', 'nosql',
41
+ // File system
42
+ 'fs', 'dir', 'tmp', 'src', 'dst', 'bin', 'lib', 'pkg',
43
+ // Operating system
44
+ 'os', 'env', 'arg', 'cli', 'cmd', 'exe', 'cwd', 'pwd',
45
+ // UI/UX
46
+ 'ui', 'ux', 'gui', 'dom', 'ref',
47
+ // Request/Response
48
+ 'req', 'res', 'ctx', 'err', 'msg', 'auth',
49
+ // Mathematics/Computing
50
+ 'max', 'min', 'avg', 'sum', 'abs', 'cos', 'sin', 'tan', 'log', 'exp',
51
+ 'pow', 'sqrt', 'std', 'var', 'int', 'num', 'idx',
52
+ // Time
53
+ 'now', 'utc', 'tz', 'ms', 'sec', 'hr', 'min', 'yr', 'mo',
54
+ // Common patterns
55
+ 'app', 'cfg', 'config', 'init', 'len', 'val', 'str', 'obj', 'arr',
56
+ 'gen', 'def', 'raw', 'new', 'old', 'pre', 'post', 'sub', 'pub',
57
+ // Programming/Framework specific
58
+ 'ts', 'js', 'jsx', 'tsx', 'py', 'rb', 'vue', 're', 'fn', 'fns', 'mod', 'opts', 'dev',
59
+ // Cloud/Infrastructure
60
+ 's3', 'ec2', 'sqs', 'sns', 'vpc', 'ami', 'iam', 'acl', 'elb', 'alb', 'nlb', 'aws',
61
+ 'ses', 'gst', 'cdk', 'btn', 'buf', 'agg', 'ocr', 'ai', 'cf', 'cfn', 'ga',
62
+ // Metrics/Performance
63
+ 'fcp', 'lcp', 'cls', 'ttfb', 'tti', 'fid', 'fps', 'qps', 'rps', 'tps', 'wpm',
64
+ // Testing & i18n
65
+ 'po', 'e2e', 'a11y', 'i18n', 'l10n', 'spy',
66
+ // Domain-specific abbreviations (context-aware)
67
+ 'sk', 'fy', 'faq', 'og', 'seo', 'cta', 'roi', 'kpi', 'ttl', 'pct',
68
+ // Technical abbreviations
69
+ 'mac', 'hex', 'esm', 'git', 'rec', 'loc', 'dup',
70
+ // Boolean helpers (these are intentional short names)
71
+ 'is', 'has', 'can', 'did', 'was', 'are',
72
+ // Date/Time context (when in date contexts)
73
+ 'd', 't', 'dt',
74
+ // Coverage metrics (industry standard: statements/branches/functions/lines)
75
+ 's', 'b', 'f', 'l',
76
+ // Common media/content abbreviations
77
+ 'vid', 'pic', 'img', 'doc', 'msg'
78
+ ]);
79
+
80
+ /**
81
+ * Convert snake_case to camelCase
82
+ */
83
+ export function snakeCaseToCamelCase(str: string): string {
84
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
85
+ }
86
+
87
+ /**
88
+ * Detect naming convention patterns across the codebase
89
+ */
90
+ export function detectNamingConventions(
91
+ files: string[],
92
+ allIssues: Array<{ type: string; [key: string]: any }>
93
+ ): {
94
+ dominantConvention: 'camelCase' | 'snake_case' | 'PascalCase' | 'mixed';
95
+ conventionScore: number;
96
+ } {
97
+ // Count conventions
98
+ const camelCaseCount = allIssues.filter(i => i.type === 'convention-mix').length;
99
+ const totalChecks = files.length * 10; // Rough estimate
100
+
101
+ if (camelCaseCount / totalChecks > 0.3) {
102
+ return { dominantConvention: 'mixed', conventionScore: 0.5 };
103
+ }
104
+
105
+ // For TypeScript/JavaScript, default to camelCase
106
+ return { dominantConvention: 'camelCase', conventionScore: 0.9 };
107
+ }