@aiready/consistency 0.3.3 → 0.3.4

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/cli.js CHANGED
@@ -31,12 +31,154 @@ var import_core3 = require("@aiready/core");
31
31
 
32
32
  // src/analyzers/naming.ts
33
33
  var import_core = require("@aiready/core");
34
+ var COMMON_SHORT_WORDS = /* @__PURE__ */ new Set([
35
+ // Full English words (1-3 letters)
36
+ "day",
37
+ "key",
38
+ "net",
39
+ "to",
40
+ "go",
41
+ "for",
42
+ "not",
43
+ "new",
44
+ "old",
45
+ "top",
46
+ "end",
47
+ "run",
48
+ "try",
49
+ "use",
50
+ "get",
51
+ "set",
52
+ "add",
53
+ "put",
54
+ "map",
55
+ "log",
56
+ "row",
57
+ "col",
58
+ "tab",
59
+ "box",
60
+ "div",
61
+ "nav",
62
+ "tag",
63
+ "any",
64
+ "all",
65
+ "one",
66
+ "two",
67
+ "out",
68
+ "off",
69
+ "on",
70
+ "yes",
71
+ "no",
72
+ "now",
73
+ "max",
74
+ "min",
75
+ "sum",
76
+ "avg",
77
+ "ref",
78
+ "src",
79
+ "dst",
80
+ "raw",
81
+ "def",
82
+ "sub",
83
+ "pub",
84
+ "pre",
85
+ "mid",
86
+ "alt",
87
+ "opt",
88
+ "tmp",
89
+ "ext",
90
+ "sep",
91
+ // Additional full words commonly flagged
92
+ "tax",
93
+ "cat",
94
+ "dog",
95
+ "car",
96
+ "bus",
97
+ "web",
98
+ "app",
99
+ "war",
100
+ "law",
101
+ "pay",
102
+ "buy",
103
+ "win",
104
+ "cut",
105
+ "hit",
106
+ "hot",
107
+ "pop",
108
+ "job",
109
+ "age",
110
+ "act",
111
+ "let",
112
+ "lot",
113
+ "bad",
114
+ "big",
115
+ "far",
116
+ "few",
117
+ "own",
118
+ "per",
119
+ "red",
120
+ "low",
121
+ "see",
122
+ "six",
123
+ "ten",
124
+ "way",
125
+ "who",
126
+ "why",
127
+ "yet",
128
+ "via",
129
+ "due",
130
+ "fee",
131
+ "fun",
132
+ "gas",
133
+ "gay",
134
+ "god",
135
+ "gun",
136
+ "guy",
137
+ "ice",
138
+ "ill",
139
+ "kid",
140
+ "mad",
141
+ "man",
142
+ "mix",
143
+ "mom",
144
+ "mrs",
145
+ "nor",
146
+ "odd",
147
+ "oil",
148
+ "pan",
149
+ "pet",
150
+ "pit",
151
+ "pot",
152
+ "pow",
153
+ "pro",
154
+ "raw",
155
+ "rep",
156
+ "rid",
157
+ "sad",
158
+ "sea",
159
+ "sit",
160
+ "sky",
161
+ "son",
162
+ "tea",
163
+ "tie",
164
+ "tip",
165
+ "van",
166
+ "war",
167
+ "win",
168
+ "won"
169
+ ]);
34
170
  var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
35
171
  // Standard identifiers
36
172
  "id",
37
173
  "uid",
38
174
  "gid",
39
175
  "pid",
176
+ // Loop counters and iterators
177
+ "i",
178
+ "j",
179
+ "k",
180
+ "n",
181
+ "m",
40
182
  // Web/Network
41
183
  "url",
42
184
  "uri",
@@ -54,6 +196,9 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
54
196
  "rss",
55
197
  "xhr",
56
198
  "ajax",
199
+ "cors",
200
+ "ws",
201
+ "wss",
57
202
  // Data formats
58
203
  "json",
59
204
  "xml",
@@ -63,12 +208,27 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
63
208
  "css",
64
209
  "svg",
65
210
  "pdf",
211
+ // File types & extensions
212
+ "img",
213
+ "txt",
214
+ "doc",
215
+ "docx",
216
+ "xlsx",
217
+ "ppt",
218
+ "md",
219
+ "rst",
220
+ "jpg",
221
+ "png",
222
+ "gif",
66
223
  // Databases
67
224
  "db",
68
225
  "sql",
69
226
  "orm",
70
227
  "dao",
71
228
  "dto",
229
+ "ddb",
230
+ "rds",
231
+ "nosql",
72
232
  // File system
73
233
  "fs",
74
234
  "dir",
@@ -85,6 +245,8 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
85
245
  "cli",
86
246
  "cmd",
87
247
  "exe",
248
+ "cwd",
249
+ "pwd",
88
250
  // UI/UX
89
251
  "ui",
90
252
  "ux",
@@ -97,6 +259,7 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
97
259
  "ctx",
98
260
  "err",
99
261
  "msg",
262
+ "auth",
100
263
  // Mathematics/Computing
101
264
  "max",
102
265
  "min",
@@ -114,12 +277,17 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
114
277
  "var",
115
278
  "int",
116
279
  "num",
280
+ "idx",
117
281
  // Time
118
282
  "now",
119
283
  "utc",
120
284
  "tz",
121
285
  "ms",
122
286
  "sec",
287
+ "hr",
288
+ "min",
289
+ "yr",
290
+ "mo",
123
291
  // Common patterns
124
292
  "app",
125
293
  "cfg",
@@ -139,13 +307,70 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
139
307
  "post",
140
308
  "sub",
141
309
  "pub",
310
+ // Programming/Framework specific
311
+ "ts",
312
+ "js",
313
+ "jsx",
314
+ "tsx",
315
+ "py",
316
+ "rb",
317
+ "vue",
318
+ "re",
319
+ "fn",
320
+ "fns",
321
+ "mod",
322
+ "opts",
323
+ "dev",
324
+ // Cloud/Infrastructure
325
+ "s3",
326
+ "ec2",
327
+ "sqs",
328
+ "sns",
329
+ "vpc",
330
+ "ami",
331
+ "iam",
332
+ "acl",
333
+ "elb",
334
+ "alb",
335
+ "nlb",
336
+ "aws",
337
+ // Metrics/Performance
338
+ "fcp",
339
+ "lcp",
340
+ "cls",
341
+ "ttfb",
342
+ "tti",
343
+ "fid",
344
+ "fps",
345
+ "qps",
346
+ "rps",
347
+ "tps",
348
+ // Testing & i18n
349
+ "po",
350
+ "e2e",
351
+ "a11y",
352
+ "i18n",
353
+ "l10n",
354
+ // Domain-specific abbreviations (context-aware)
355
+ "sk",
356
+ "fy",
357
+ "faq",
358
+ "og",
359
+ "seo",
360
+ "cta",
361
+ "roi",
362
+ "kpi",
142
363
  // Boolean helpers (these are intentional short names)
143
364
  "is",
144
365
  "has",
145
366
  "can",
146
367
  "did",
147
368
  "was",
148
- "are"
369
+ "are",
370
+ // Date/Time context (when in date contexts)
371
+ "d",
372
+ "t",
373
+ "dt"
149
374
  ]);
150
375
  async function analyzeNaming(files) {
151
376
  const issues = [];
@@ -158,14 +383,22 @@ async function analyzeNaming(files) {
158
383
  }
159
384
  function analyzeFileNaming(file, content) {
160
385
  const issues = [];
386
+ const isTestFile = file.match(/\.(test|spec)\.(ts|tsx|js|jsx)$/);
161
387
  const lines = content.split("\n");
162
388
  lines.forEach((line, index) => {
163
389
  const lineNumber = index + 1;
164
390
  const singleLetterMatches = line.matchAll(/\b(?:const|let|var)\s+([a-hm-z])\s*=/gi);
165
391
  for (const match of singleLetterMatches) {
166
392
  const letter = match[1].toLowerCase();
167
- const isInLoopContext = line.includes("for") || line.includes(".map") || line.includes(".filter") || line.includes(".forEach") || line.includes(".reduce");
168
- if (!isInLoopContext && !["x", "y", "z", "i", "j", "k", "l", "n", "m"].includes(letter)) {
393
+ const isInLoopContext = line.includes("for") || /\.(map|filter|forEach|reduce|find|some|every)\s*\(/.test(line) || line.includes("=>") || // Arrow function
394
+ /\w+\s*=>\s*/.test(line);
395
+ const isI18nContext = line.includes("useTranslation") || line.includes("i18n.t") || /\bt\s*\(['"]/.test(line);
396
+ const isArrowFunctionParam = /\(\s*[a-z]\s*(?:,\s*[a-z]\s*)*\)\s*=>/.test(line) || // (s) => or (a, b) =>
397
+ /[a-z]\s*=>/.test(line);
398
+ if (!isInLoopContext && !isI18nContext && !isArrowFunctionParam && !["x", "y", "z", "i", "j", "k", "l", "n", "m"].includes(letter)) {
399
+ if (isTestFile && ["a", "b", "c", "d", "e", "f", "s"].includes(letter)) {
400
+ continue;
401
+ }
169
402
  issues.push({
170
403
  file,
171
404
  line: lineNumber,
@@ -179,16 +412,35 @@ function analyzeFileNaming(file, content) {
179
412
  const abbreviationMatches = line.matchAll(/\b(?:const|let|var)\s+([a-z]{1,3})(?=[A-Z]|_|\s*=)/g);
180
413
  for (const match of abbreviationMatches) {
181
414
  const abbrev = match[1].toLowerCase();
182
- if (!ACCEPTABLE_ABBREVIATIONS.has(abbrev)) {
183
- issues.push({
184
- file,
185
- line: lineNumber,
186
- type: "abbreviation",
187
- identifier: match[1],
188
- severity: "info",
189
- suggestion: `Consider using full word instead of abbreviation '${match[1]}'`
190
- });
415
+ if (COMMON_SHORT_WORDS.has(abbrev)) {
416
+ continue;
191
417
  }
418
+ if (ACCEPTABLE_ABBREVIATIONS.has(abbrev)) {
419
+ continue;
420
+ }
421
+ const isArrowFunctionParam = /\(\s*[a-z]\s*(?:,\s*[a-z]\s*)*\)\s*=>/.test(line) || // (s) => or (a, b) =>
422
+ new RegExp(`\\b${abbrev}\\s*=>`).test(line);
423
+ if (isArrowFunctionParam) {
424
+ continue;
425
+ }
426
+ if (abbrev.length <= 2) {
427
+ const isDateTimeContext = /date|time|day|hour|minute|second|timestamp/i.test(line);
428
+ if (isDateTimeContext && ["d", "t", "dt"].includes(abbrev)) {
429
+ continue;
430
+ }
431
+ const isUserContext = /user|auth|account/i.test(line);
432
+ if (isUserContext && abbrev === "u") {
433
+ continue;
434
+ }
435
+ }
436
+ issues.push({
437
+ file,
438
+ line: lineNumber,
439
+ type: "abbreviation",
440
+ identifier: match[1],
441
+ severity: "info",
442
+ suggestion: `Consider using full word instead of abbreviation '${match[1]}'`
443
+ });
192
444
  }
193
445
  if (file.match(/\.(ts|tsx|js|jsx)$/)) {
194
446
  const camelCaseVars = line.match(/\b(?:const|let|var)\s+([a-z][a-zA-Z0-9]*)\s*=/);
@@ -221,11 +473,22 @@ function analyzeFileNaming(file, content) {
221
473
  const functionMatches = line.matchAll(/function\s+([a-z][a-zA-Z0-9]*)/g);
222
474
  for (const match of functionMatches) {
223
475
  const name = match[1];
476
+ const isKeyword = ["for", "if", "else", "while", "do", "switch", "case", "break", "continue", "return", "throw", "try", "catch", "finally", "with", "yield", "await"].includes(name);
477
+ if (isKeyword) {
478
+ continue;
479
+ }
480
+ const isEntryPoint = ["main", "init", "setup", "bootstrap"].includes(name);
481
+ if (isEntryPoint) {
482
+ continue;
483
+ }
224
484
  const isFactoryPattern = name.match(/(Factory|Builder|Creator|Generator)$/);
225
485
  const isEventHandler = name.match(/^on[A-Z]/);
226
- const isDescriptiveLong = name.length > 20;
486
+ const isDescriptiveLong = name.length > 15;
487
+ const isDescriptivePattern = name.match(/^(default|total|count|sum|avg|max|min|initial|current|previous|next)\w+/) || name.match(/\w+(Count|Total|Sum|Average|List|Map|Set|Config|Settings|Options|Props)$/);
488
+ const capitalCount = (name.match(/[A-Z]/g) || []).length;
489
+ const isCompoundWord = capitalCount >= 3;
227
490
  const hasActionVerb = name.match(/^(get|set|is|has|can|should|create|update|delete|fetch|load|save|process|handle|validate|check|find|search|filter|map|reduce|make|do|run|start|stop|build|parse|format|render|calculate|compute|generate|transform|convert|normalize|sanitize|encode|decode|compress|extract|merge|split|join|sort|compare|test|verify|ensure|apply|execute|invoke|call|emit|dispatch|trigger|listen|subscribe|unsubscribe|add|remove|clear|reset|toggle|enable|disable|open|close|connect|disconnect|send|receive|read|write|import|export|register|unregister|mount|unmount)/);
228
- if (!hasActionVerb && !isFactoryPattern && !isEventHandler && !isDescriptiveLong) {
491
+ if (!hasActionVerb && !isFactoryPattern && !isEventHandler && !isDescriptiveLong && !isDescriptivePattern && !isCompoundWord) {
229
492
  issues.push({
230
493
  file,
231
494
  line: lineNumber,
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  analyzeConsistency
4
- } from "./chunk-LUAREV6A.mjs";
4
+ } from "./chunk-TLVLM3M5.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { Command } from "commander";