Configuration overview
How to configure Debt-collector
By default, Debt Collector will look for a configuration file in the current working directory:
./debt-collector.config.jsEvery command allows you to override this behavior using the --config or -c flag followed by the path to your configuration file.
Example:
debt-collector check --config ./configs/debt-collector.jsConfiguration Structure
The configuration file should export a JavaScript object with the following structure:
type Config = {
// Glob patterns for files to analyze
includes: string | string[];
// Optional glob patterns for files to exclude
excludes?: string | string[];
// Rules to check in files
fileRules: {
// Required fields
id: string; // Unique identifier in SNAKE_CASE
title: string; // Human-readable description
debtScore: number; // Score to add for each match
// Optional fields
description?: string; // Detailed explanation of the rule
howTo?: string; // Instructions on how to fix the issue
include?: string | string[]; // Rule-specific file patterns
exclude?: string | string[]; // Rule-specific file exclusions
tags?: string | string[]; // Categories for filtering rules
matchRule?: (context: MatchRuleContext) => number; // Rule matching logic
}[];
// Optional walk command configuration
walkConfig?: {
gitCommand: string; // Git command to get revisions
parser: (gitResult: string) => {hash: string; name: string; date: string}[]; // Parse git command output
limit?: number; // Maximum number of revisions to analyze
report?: {
// Report configuration options
};
};
}Rule Types
File Rules
File rules are used to analyze file contents and identify patterns. Each rule can have:
Basic Properties:
id: Unique identifier in SNAKE_CASE (e.g.,NO_FOO_VARIABLES)title: Human-readable descriptiondebtScore: Number of points to add for each matchdescription: Optional detailed explanationhowTo: Optional instructions on how to fix the issue
File Filtering:
include: Glob patterns for files to checkexclude: Glob patterns for files to ignoretags: Categories for filtering rules
Matching Logic: The
matchRulefunction receives a context object with utilities:
Examples
Basic Configuration
Walk Command Configuration
Best Practices
Rule IDs: Use descriptive, uppercase SNAKE_CASE identifiers
Debt Scores: Use consistent scoring based on impact and effort
File Patterns: Be specific with include/exclude patterns
Tags: Use meaningful categories for better organization
Descriptions: Provide clear explanations and fix instructions
Testing: Test rules with various file types and content
Maintenance: Review and update rules periodically
Common Patterns
Finding Specific Code Patterns
Counting Multiple Patterns
Complex Pattern Matching
Last updated