Config loading

Source: src/engine/config/loader.ts

Resolves and merges user configuration with built-in defaults. A fallback chain means nestjs-doctor runs with no configuration at all. A config file then changes which files are scanned, which rules are enabled, and which diagnostics are ignored.

Input is the project root plus an optional explicit config path:

targetPath: string      // project root directory
configPath?: string     // explicit config file path (from --config flag)

The result is the resolved config:

interface NestjsDoctorConfig {
  include: string[]                                // glob patterns to scan
  exclude: string[]                                // glob patterns to skip
  minScore?: number                                // CI threshold (0-100)
  rules?: Record<string, RuleOverride | boolean>   // per-rule overrides
  categories?: Partial<Record<Category, boolean>>  // enable/disable categories
  ignore?: {
    rules?: string[]     // rule IDs to suppress
    files?: string[]     // file patterns to ignore
  }
}

How it works

Resolution order

The loader tries these locations in order and uses the first match:

  1. Explicit path: if --config path/to/config.json was passed. This bypasses the rest of the chain.
  2. nestjs-doctor.config.json: in the project root
  3. .nestjs-doctor.json: dotfile variant
  4. package.json: the "nestjs-doctor" key
  5. Built-in defaults: if nothing else is found

Merge strategy

User config is merged with DEFAULT_CONFIG:

const DEFAULT_CONFIG = {
  include: ["**/*.ts"],
  exclude: [
    "**/node_modules/**", "**/dist/**", "**/build/**", "**/coverage/**",
    "**/*.spec.ts", "**/*.test.ts", "**/*.e2e-spec.ts", "**/*.e2e-test.ts",
    "**/*.d.ts", "**/test/**", "**/tests/**", "**/__tests__/**",
    "**/__mocks__/**", "**/__fixtures__/**", "**/mock/**", "**/mocks/**",
    "**/*.mock.ts", "**/seeder/**", "**/seeders/**",
    "**/*.seed.ts", "**/*.seeder.ts",
    "*.config.ts", "*.config.js", "*.config.mjs",
    "*.config.cjs", "*.config.mts", "*.config.cts",
  ],
}

Key merge behaviors:

  • exclude: additive. Your patterns are appended to the defaults, so safety exclusions like node_modules are never dropped by accident.
  • include: replaces the default entirely. If you set it, only your patterns are used.
  • rules and categories: shallow-merged.
  • ignore: replaces the default, which is empty.