All files / src/utils config-loader.ts

100% Statements 9/9
87.5% Branches 7/8
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                      6x 6x 6x     6x 6x 6x     6x 6x   6x                                  
import { loadConfig } from '@aiready/core';
import { dirname } from 'path';
import {
  COMMON_SHORT_WORDS,
  ACCEPTABLE_ABBREVIATIONS,
} from '../analyzers/naming-constants';
 
/**
 * Configuration for naming analyzers
 */
export interface NamingConfig {
  customAbbreviations: Set<string>;
  customShortWords: Set<string>;
  disabledChecks: Set<string>;
  allAbbreviations: Set<string>;
  allShortWords: Set<string>;
}
 
/**
 * Loads and merges naming configuration for consistency analyzers
 * Extracts common config loading logic used by both naming.ts and naming-ast.ts
 *
 * @param files - Array of files being analyzed (used to determine project root)
 * @returns Merged configuration with custom and default abbreviations/short words
 */
export async function loadNamingConfig(files: string[]): Promise<NamingConfig> {
  // Load config from the first file's directory (or project root)
  const rootDir = files.length > 0 ? dirname(files[0]) : process.cwd();
  const config = await loadConfig(rootDir);
  const consistencyConfig = config?.tools?.['consistency'];
 
  // Extract custom configuration
  const customAbbreviations = new Set(
    (consistencyConfig?.acceptedAbbreviations as string[]) || []
  );
  const customShortWords = new Set(
    (consistencyConfig?.shortWords as string[]) || []
  );
  const disabledChecks = new Set(
    (consistencyConfig?.disableChecks as string[]) || []
  );
 
  // Merge with defaults
  const allAbbreviations = new Set([
    ...ACCEPTABLE_ABBREVIATIONS,
    ...customAbbreviations,
  ]);
  const allShortWords = new Set([...COMMON_SHORT_WORDS, ...customShortWords]);
 
  return {
    customAbbreviations,
    customShortWords,
    disabledChecks,
    allAbbreviations,
    allShortWords,
  };
}