@aiready/consistency 0.8.31 → 0.8.32

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