Config Loading
Source: src/core/config-loader.ts
What
Resolves and merges user configuration with built-in defaults.
Why
Users need to customize which files to scan, which rules to enable/disable, and which diagnostics to ignore. The config loader provides a fallback chain so nestjs-doctor works without configuration but remains fully customizable.
Input
targetPath: string // project root directory
configPath?: string // explicit config file path (from --config flag)
Output
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:
- Explicit path — if
--config path/to/config.jsonwas passed nestjs-doctor.config.json— in the project root.nestjs-doctor.json— dotfile variantpackage.json— the"nestjs-doctor"key- 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",
],
}
Key merge behaviors:
excludeis additive — your patterns are appended to the defaults, so safety exclusions likenode_modulesare never accidentally removedincludereplaces the default entirely — if you set it, only your patterns are usedrulesandcategoriesare shallow-mergedignorereplaces the default (empty) ignore config
Debugging Tips
- If a file is not being scanned, check whether it matches an exclude pattern. The default excludes are extensive (test files, mocks, seeders, declaration files).
- If a rule is not running, check both
rules(individual toggle) andcategories(category-level toggle) in config. - Use
--configto point to a specific config file and bypass the search chain.