@aiready/consistency 0.6.7 → 0.6.10

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.
@@ -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
+ }