code complexity & repetition analysis tool
1# Configuration
2
3Mccabre can be configured via config files and CLI flags.
4
5## Configuration Priority
6
71. **CLI flags** (highest priority)
82. **Config file** (`mccabre.toml`)
93. **Defaults** (lowest priority)
10
11CLI flags override config file settings.
12
13## Config File
14
15Create a `mccabre.toml` file in your project root:
16
17```toml
18[complexity]
19warning_threshold = 10
20error_threshold = 20
21
22[clones]
23enabled = true
24min_tokens = 30
25
26[files]
27respect_gitignore = true
28```
29
30### Generating a Config File
31
32You can generate a config file using the `dump-config` command:
33
34```bash
35# Save default config to current directory
36mccabre dump-config -o mccabre.toml
37
38# Save to a specific location
39mccabre dump-config -o /path/to/config.toml
40
41# Save to a directory (creates mccabre.toml in that directory)
42mccabre dump-config -o ./configs/
43
44# Load existing config and save to new location
45mccabre dump-config -c old-config.toml -o new-config.toml
46```
47
48This is useful for:
49
50- Creating a starting point for customization
51- Copying configurations between projects
52- Version controlling your settings
53
54## Configuration Options
55
56### Complexity Settings
57
58```toml
59[complexity]
60warning_threshold = 10 # Yellow warning at this level
61error_threshold = 20 # Red error at this level
62```
63
64**Defaults:**
65
66- `warning_threshold`: 10
67- `error_threshold`: 20
68
69**CLI Override:**
70
71```bash
72mccabre analyze --threshold 15
73```
74
75### Clone Detection Settings
76
77```toml
78[clones]
79enabled = true # Enable/disable clone detection
80min_tokens = 30 # Minimum token sequence length
81```
82
83**Defaults:**
84
85- `enabled`: true
86- `min_tokens`: 30
87
88**CLI Override:**
89
90```bash
91mccabre analyze --min-tokens 25
92```
93
94### File Settings
95
96```toml
97[files]
98respect_gitignore = true # Honor .gitignore files
99```
100
101**Defaults:**
102
103- `respect_gitignore`: true
104
105**CLI Override:**
106
107```bash
108mccabre analyze --no-gitignore
109```
110
111## Loading Configuration
112
113### Automatic Discovery
114
115Mccabre searches for config files in this order:
116
1171. `mccabre.toml`
1182. `.mccabre.toml`
1193. `.mccabre/config.toml`
120
121The first file found is used.
122
123### Explicit Path
124
125Specify a config file:
126
127```bash
128mccabre analyze --config /path/to/config.toml
129```
130
131### No Config File
132
133If no config file exists, defaults are used.
134
135## Example Configurations
136
137### Strict Mode
138
139For critical codebases:
140
141```toml
142[complexity]
143warning_threshold = 5
144error_threshold = 10
145
146[clones]
147enabled = true
148min_tokens = 20
149
150[files]
151respect_gitignore = true
152```
153
154### Lenient Mode
155
156For legacy codebases:
157
158```toml
159[complexity]
160warning_threshold = 20
161error_threshold = 40
162
163[clones]
164enabled = true
165min_tokens = 50
166
167[files]
168respect_gitignore = true
169```
170
171### Clone-Focused
172
173Focus on duplication:
174
175```toml
176[complexity]
177warning_threshold = 100 # Effectively disable
178error_threshold = 200
179
180[clones]
181enabled = true
182min_tokens = 15 # Very sensitive
183
184[files]
185respect_gitignore = true
186```
187
188## Per-Project Settings
189
190Different projects can have different configs:
191
192```bash
193project-a/
194 ├── mccabre.toml # Strict settings
195 └── src/
196
197project-b/
198 ├── mccabre.toml # Lenient settings
199 └── src/
200```
201
202Each project's config is automatically loaded when analyzing that directory.
203
204## Viewing Current Configuration
205
206Check what settings are active:
207
208```bash
209mccabre dump-config
210```
211
212Output:
213
214```text
215CONFIGURATION
216================================================================================
217
218Complexity Settings:
219 Warning threshold: 10
220 Error threshold: 20
221
222Clone Detection Settings:
223 Enabled: true
224 Minimum tokens: 30
225
226File Settings:
227 Respect .gitignore: true
228```
229
230## Ignoring Files
231
232Use `.gitignore` to exclude files/directories:
233
234```text
235# .gitignore
236target/
237node_modules/
238build/
239*.generated.rs
240```
241
242Mccabre automatically respects these exclusions.
243
244To analyze everything (ignore gitignore):
245
246```bash
247mccabre analyze . --no-gitignore
248```
249
250## See Also
251
252- [CLI Reference](./cli-reference.md)
253- [Cyclomatic Complexity](./cyclomatic-complexity.md)
254- [Clone Detection](./clone-detection.md)