@aiready/consistency 0.6.6 → 0.6.8

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
@@ -29,10 +29,6 @@ var import_commander = require("commander");
29
29
  // src/analyzer.ts
30
30
  var import_core3 = require("@aiready/core");
31
31
 
32
- // src/analyzers/naming-ast.ts
33
- var import_core = require("@aiready/core");
34
- var import_path = require("path");
35
-
36
32
  // src/utils/ast-parser.ts
37
33
  var import_typescript_estree = require("@typescript-eslint/typescript-estree");
38
34
  var import_fs = require("fs");
@@ -457,6 +453,10 @@ function isAcceptableInContext(name, context, options) {
457
453
  return false;
458
454
  }
459
455
 
456
+ // src/utils/config-loader.ts
457
+ var import_core = require("@aiready/core");
458
+ var import_path = require("path");
459
+
460
460
  // src/analyzers/naming-constants.ts
461
461
  var COMMON_SHORT_WORDS = /* @__PURE__ */ new Set([
462
462
  // Full English words (1-3 letters)
@@ -841,9 +841,8 @@ var ACCEPTABLE_ABBREVIATIONS = /* @__PURE__ */ new Set([
841
841
  "msg"
842
842
  ]);
843
843
 
844
- // src/analyzers/naming-ast.ts
845
- async function analyzeNamingAST(files) {
846
- const issues = [];
844
+ // src/utils/config-loader.ts
845
+ async function loadNamingConfig(files) {
847
846
  const rootDir = files.length > 0 ? (0, import_path.dirname)(files[0]) : process.cwd();
848
847
  const config = await (0, import_core.loadConfig)(rootDir);
849
848
  const consistencyConfig = config?.tools?.["consistency"];
@@ -852,6 +851,19 @@ async function analyzeNamingAST(files) {
852
851
  const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
853
852
  const allAbbreviations = /* @__PURE__ */ new Set([...ACCEPTABLE_ABBREVIATIONS, ...customAbbreviations]);
854
853
  const allShortWords = /* @__PURE__ */ new Set([...COMMON_SHORT_WORDS, ...customShortWords]);
854
+ return {
855
+ customAbbreviations,
856
+ customShortWords,
857
+ disabledChecks,
858
+ allAbbreviations,
859
+ allShortWords
860
+ };
861
+ }
862
+
863
+ // src/analyzers/naming-ast.ts
864
+ async function analyzeNamingAST(files) {
865
+ const issues = [];
866
+ const { allAbbreviations, allShortWords, disabledChecks } = await loadNamingConfig(files);
855
867
  for (const file of files) {
856
868
  try {
857
869
  const ast = parseFile(file);
@@ -1177,7 +1189,7 @@ async function analyzeImportStyles(files) {
1177
1189
  for (const file of files) {
1178
1190
  const content = await (0, import_core2.readFileContent)(file);
1179
1191
  const hasESM = content.match(/^import\s+/m);
1180
- const hasCJS = content.match(/require\s*\(/);
1192
+ const hasCJS = hasActualRequireCalls(content);
1181
1193
  if (hasESM && hasCJS) {
1182
1194
  patterns.mixed.push(file);
1183
1195
  } else if (hasESM) {
@@ -1213,6 +1225,15 @@ async function analyzeImportStyles(files) {
1213
1225
  }
1214
1226
  return issues;
1215
1227
  }
1228
+ function hasActualRequireCalls(content) {
1229
+ let cleaned = content.replace(/\/\/.*$/gm, "");
1230
+ cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, "");
1231
+ cleaned = cleaned.replace(/"[^"\n]*"/g, '""');
1232
+ cleaned = cleaned.replace(/'[^'\n]*'/g, "''");
1233
+ cleaned = cleaned.replace(/`[^`]*`/g, "``");
1234
+ cleaned = cleaned.replace(/\/[^/\n]*require[^/\n]*\/[gimsuvy]*/g, "");
1235
+ return /require\s*\(/.test(cleaned);
1236
+ }
1216
1237
 
1217
1238
  // src/analyzer.ts
1218
1239
  async function analyzeConsistency(options) {
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  analyzeConsistency
4
- } from "./chunk-WTBDNCEN.mjs";
4
+ } from "./chunk-HPG7P6PD.mjs";
5
5
 
6
6
  // src/cli.ts
7
7
  import { Command } from "commander";
package/dist/index.js CHANGED
@@ -31,10 +31,6 @@ module.exports = __toCommonJS(index_exports);
31
31
  // src/analyzer.ts
32
32
  var import_core3 = require("@aiready/core");
33
33
 
34
- // src/analyzers/naming-ast.ts
35
- var import_core = require("@aiready/core");
36
- var import_path = require("path");
37
-
38
34
  // src/utils/ast-parser.ts
39
35
  var import_typescript_estree = require("@typescript-eslint/typescript-estree");
40
36
  var import_fs = require("fs");
@@ -459,6 +455,10 @@ function isAcceptableInContext(name, context, options) {
459
455
  return false;
460
456
  }
461
457
 
458
+ // src/utils/config-loader.ts
459
+ var import_core = require("@aiready/core");
460
+ var import_path = require("path");
461
+
462
462
  // src/analyzers/naming-constants.ts
463
463
  var COMMON_SHORT_WORDS = /* @__PURE__ */ new Set([
464
464
  // Full English words (1-3 letters)
@@ -854,9 +854,8 @@ function detectNamingConventions(files, allIssues) {
854
854
  return { dominantConvention: "camelCase", conventionScore: 0.9 };
855
855
  }
856
856
 
857
- // src/analyzers/naming-ast.ts
858
- async function analyzeNamingAST(files) {
859
- const issues = [];
857
+ // src/utils/config-loader.ts
858
+ async function loadNamingConfig(files) {
860
859
  const rootDir = files.length > 0 ? (0, import_path.dirname)(files[0]) : process.cwd();
861
860
  const config = await (0, import_core.loadConfig)(rootDir);
862
861
  const consistencyConfig = config?.tools?.["consistency"];
@@ -865,6 +864,19 @@ async function analyzeNamingAST(files) {
865
864
  const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
866
865
  const allAbbreviations = /* @__PURE__ */ new Set([...ACCEPTABLE_ABBREVIATIONS, ...customAbbreviations]);
867
866
  const allShortWords = /* @__PURE__ */ new Set([...COMMON_SHORT_WORDS, ...customShortWords]);
867
+ return {
868
+ customAbbreviations,
869
+ customShortWords,
870
+ disabledChecks,
871
+ allAbbreviations,
872
+ allShortWords
873
+ };
874
+ }
875
+
876
+ // src/analyzers/naming-ast.ts
877
+ async function analyzeNamingAST(files) {
878
+ const issues = [];
879
+ const { allAbbreviations, allShortWords, disabledChecks } = await loadNamingConfig(files);
868
880
  for (const file of files) {
869
881
  try {
870
882
  const ast = parseFile(file);
@@ -1190,7 +1202,7 @@ async function analyzeImportStyles(files) {
1190
1202
  for (const file of files) {
1191
1203
  const content = await (0, import_core2.readFileContent)(file);
1192
1204
  const hasESM = content.match(/^import\s+/m);
1193
- const hasCJS = content.match(/require\s*\(/);
1205
+ const hasCJS = hasActualRequireCalls(content);
1194
1206
  if (hasESM && hasCJS) {
1195
1207
  patterns.mixed.push(file);
1196
1208
  } else if (hasESM) {
@@ -1226,6 +1238,15 @@ async function analyzeImportStyles(files) {
1226
1238
  }
1227
1239
  return issues;
1228
1240
  }
1241
+ function hasActualRequireCalls(content) {
1242
+ let cleaned = content.replace(/\/\/.*$/gm, "");
1243
+ cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, "");
1244
+ cleaned = cleaned.replace(/"[^"\n]*"/g, '""');
1245
+ cleaned = cleaned.replace(/'[^'\n]*'/g, "''");
1246
+ cleaned = cleaned.replace(/`[^`]*`/g, "``");
1247
+ cleaned = cleaned.replace(/\/[^/\n]*require[^/\n]*\/[gimsuvy]*/g, "");
1248
+ return /require\s*\(/.test(cleaned);
1249
+ }
1229
1250
 
1230
1251
  // src/analyzer.ts
1231
1252
  async function analyzeConsistency(options) {
@@ -1375,15 +1396,9 @@ function generateRecommendations(namingIssues, patternIssues) {
1375
1396
 
1376
1397
  // src/analyzers/naming.ts
1377
1398
  var import_core4 = require("@aiready/core");
1378
- var import_path2 = require("path");
1379
1399
  async function analyzeNaming(files) {
1380
1400
  const issues = [];
1381
- const rootDir = files.length > 0 ? (0, import_path2.dirname)(files[0]) : process.cwd();
1382
- const config = await (0, import_core4.loadConfig)(rootDir);
1383
- const consistencyConfig = config?.tools?.["consistency"];
1384
- const customAbbreviations = new Set(consistencyConfig?.acceptedAbbreviations || []);
1385
- const customShortWords = new Set(consistencyConfig?.shortWords || []);
1386
- const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
1401
+ const { customAbbreviations, customShortWords, disabledChecks } = await loadNamingConfig(files);
1387
1402
  for (const file of files) {
1388
1403
  const content = await (0, import_core4.readFileContent)(file);
1389
1404
  const fileIssues = analyzeFileNaming(file, content, customAbbreviations, customShortWords, disabledChecks);
package/dist/index.mjs CHANGED
@@ -5,20 +5,15 @@ import {
5
5
  analyzeNamingAST,
6
6
  analyzePatterns,
7
7
  detectNamingConventions,
8
+ loadNamingConfig,
8
9
  snakeCaseToCamelCase
9
- } from "./chunk-WTBDNCEN.mjs";
10
+ } from "./chunk-HPG7P6PD.mjs";
10
11
 
11
12
  // src/analyzers/naming.ts
12
- import { readFileContent, loadConfig } from "@aiready/core";
13
- import { dirname } from "path";
13
+ import { readFileContent } from "@aiready/core";
14
14
  async function analyzeNaming(files) {
15
15
  const issues = [];
16
- const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
17
- const config = await loadConfig(rootDir);
18
- const consistencyConfig = config?.tools?.["consistency"];
19
- const customAbbreviations = new Set(consistencyConfig?.acceptedAbbreviations || []);
20
- const customShortWords = new Set(consistencyConfig?.shortWords || []);
21
- const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
16
+ const { customAbbreviations, customShortWords, disabledChecks } = await loadNamingConfig(files);
22
17
  for (const file of files) {
23
18
  const content = await readFileContent(file);
24
19
  const fileIssues = analyzeFileNaming(file, content, customAbbreviations, customShortWords, disabledChecks);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/consistency",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
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.4"
46
+ "@aiready/core": "0.7.5"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^22.10.5",
@@ -1,6 +1,4 @@
1
1
  import { TSESTree } from '@typescript-eslint/typescript-estree';
2
- import { loadConfig } from '@aiready/core';
3
- import { dirname } from 'path';
4
2
  import type { NamingIssue } from '../types';
5
3
  import {
6
4
  parseFile,
@@ -18,10 +16,7 @@ import {
18
16
  isAcceptableInContext,
19
17
  calculateComplexity,
20
18
  } from '../utils/context-detector';
21
- import {
22
- COMMON_SHORT_WORDS,
23
- ACCEPTABLE_ABBREVIATIONS,
24
- } from './naming-constants';
19
+ import { loadNamingConfig } from '../utils/config-loader';
25
20
 
26
21
  /**
27
22
  * AST-based naming analyzer
@@ -29,18 +24,8 @@ import {
29
24
  export async function analyzeNamingAST(files: string[]): Promise<NamingIssue[]> {
30
25
  const issues: NamingIssue[] = [];
31
26
 
32
- // Load config
33
- const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
34
- const config = await loadConfig(rootDir);
35
- const consistencyConfig = config?.tools?.['consistency'];
36
-
37
- // Merge custom configuration
38
- const customAbbreviations = new Set(consistencyConfig?.acceptedAbbreviations || []);
39
- const customShortWords = new Set(consistencyConfig?.shortWords || []);
40
- const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
41
-
42
- const allAbbreviations = new Set([...ACCEPTABLE_ABBREVIATIONS, ...customAbbreviations]);
43
- const allShortWords = new Set([...COMMON_SHORT_WORDS, ...customShortWords]);
27
+ // Load and merge configuration
28
+ const { allAbbreviations, allShortWords, disabledChecks } = await loadNamingConfig(files);
44
29
 
45
30
  for (const file of files) {
46
31
  try {
@@ -1,11 +1,11 @@
1
- import { readFileContent, loadConfig } from '@aiready/core';
1
+ import { readFileContent } from '@aiready/core';
2
2
  import type { NamingIssue } from '../types';
3
- import { dirname } from 'path';
4
3
  import {
5
4
  COMMON_SHORT_WORDS,
6
5
  ACCEPTABLE_ABBREVIATIONS,
7
6
  snakeCaseToCamelCase,
8
7
  } from './naming-constants';
8
+ import { loadNamingConfig } from '../utils/config-loader';
9
9
 
10
10
  /**
11
11
  * Analyzes naming conventions and quality
@@ -13,15 +13,8 @@ import {
13
13
  export async function analyzeNaming(files: string[]): Promise<NamingIssue[]> {
14
14
  const issues: NamingIssue[] = [];
15
15
 
16
- // Load config from the first file's directory (or project root)
17
- const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
18
- const config = await loadConfig(rootDir);
19
- const consistencyConfig = config?.tools?.['consistency'];
20
-
21
- // Merge custom abbreviations and short words with defaults
22
- const customAbbreviations = new Set(consistencyConfig?.acceptedAbbreviations || []);
23
- const customShortWords = new Set(consistencyConfig?.shortWords || []);
24
- const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
16
+ // Load and merge configuration
17
+ const { customAbbreviations, customShortWords, disabledChecks } = await loadNamingConfig(files);
25
18
 
26
19
  for (const file of files) {
27
20
  const content = await readFileContent(file);
@@ -135,7 +135,12 @@ async function analyzeImportStyles(files: string[]): Promise<PatternIssue[]> {
135
135
  for (const file of files) {
136
136
  const content = await readFileContent(file);
137
137
  const hasESM = content.match(/^import\s+/m);
138
- const hasCJS = content.match(/require\s*\(/);
138
+
139
+ // Check for actual CommonJS require() calls, excluding:
140
+ // - String literals: "require('...') or 'require('...')
141
+ // - Regex patterns: /require\(/
142
+ // - Comments: // require( or /* require( */
143
+ const hasCJS = hasActualRequireCalls(content);
139
144
 
140
145
  if (hasESM && hasCJS) {
141
146
  patterns.mixed.push(file);
@@ -179,6 +184,36 @@ async function analyzeImportStyles(files: string[]): Promise<PatternIssue[]> {
179
184
  return issues;
180
185
  }
181
186
 
187
+ /**
188
+ * Detects actual require() calls, excluding false positives
189
+ * Filters out require() in:
190
+ * - String literals (single/double/template quotes)
191
+ * - Regex patterns
192
+ * - Single-line comments (//)
193
+ * - Multi-line comments
194
+ */
195
+ function hasActualRequireCalls(content: string): boolean {
196
+ // Simple heuristic: remove obvious false positives
197
+ // 1. Remove single-line comments
198
+ let cleaned = content.replace(/\/\/.*$/gm, '');
199
+
200
+ // 2. Remove multi-line comments (non-greedy)
201
+ cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, '');
202
+
203
+ // 3. Remove string literals - use simpler regex to avoid backtracking
204
+ // Match strings but don't try to be perfect, just remove obvious ones
205
+ cleaned = cleaned.replace(/"[^"\n]*"/g, '""');
206
+ cleaned = cleaned.replace(/'[^'\n]*'/g, "''");
207
+ cleaned = cleaned.replace(/`[^`]*`/g, '``');
208
+
209
+ // 4. Simple regex detection: if we see /require in the line, likely a regex pattern
210
+ // Remove lines that look like regex patterns with require
211
+ cleaned = cleaned.replace(/\/[^/\n]*require[^/\n]*\/[gimsuvy]*/g, '');
212
+
213
+ // Now check for require( in the cleaned content
214
+ return /require\s*\(/.test(cleaned);
215
+ }
216
+
182
217
  /**
183
218
  * Analyzes API design consistency
184
219
  */
@@ -0,0 +1,48 @@
1
+ import { loadConfig } from '@aiready/core';
2
+ import { dirname } from 'path';
3
+ import {
4
+ COMMON_SHORT_WORDS,
5
+ ACCEPTABLE_ABBREVIATIONS,
6
+ } from '../analyzers/naming-constants';
7
+
8
+ /**
9
+ * Configuration for naming analyzers
10
+ */
11
+ export interface NamingConfig {
12
+ customAbbreviations: Set<string>;
13
+ customShortWords: Set<string>;
14
+ disabledChecks: Set<string>;
15
+ allAbbreviations: Set<string>;
16
+ allShortWords: Set<string>;
17
+ }
18
+
19
+ /**
20
+ * Loads and merges naming configuration for consistency analyzers
21
+ * Extracts common config loading logic used by both naming.ts and naming-ast.ts
22
+ *
23
+ * @param files - Array of files being analyzed (used to determine project root)
24
+ * @returns Merged configuration with custom and default abbreviations/short words
25
+ */
26
+ export async function loadNamingConfig(files: string[]): Promise<NamingConfig> {
27
+ // Load config from the first file's directory (or project root)
28
+ const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
29
+ const config = await loadConfig(rootDir);
30
+ const consistencyConfig = config?.tools?.['consistency'];
31
+
32
+ // Extract custom configuration
33
+ const customAbbreviations = new Set(consistencyConfig?.acceptedAbbreviations || []);
34
+ const customShortWords = new Set(consistencyConfig?.shortWords || []);
35
+ const disabledChecks = new Set(consistencyConfig?.disableChecks || []);
36
+
37
+ // Merge with defaults
38
+ const allAbbreviations = new Set([...ACCEPTABLE_ABBREVIATIONS, ...customAbbreviations]);
39
+ const allShortWords = new Set([...COMMON_SHORT_WORDS, ...customShortWords]);
40
+
41
+ return {
42
+ customAbbreviations,
43
+ customShortWords,
44
+ disabledChecks,
45
+ allAbbreviations,
46
+ allShortWords,
47
+ };
48
+ }