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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//! Code metrics calculation for software quality analysis.
//!
//! This module provides various metrics for analyzing code quality:
//!
//! - **Complexity Metrics**: Cyclomatic, cognitive, and Halstead complexity
//! - **Size Metrics**: Lines of code (LOC), function count
//! - **Coupling Metrics**: Afferent/efferent coupling, instability, main sequence analysis
//! - **Cohesion Metrics**: LCOM variants for class cohesion analysis
//!
//! # Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_complexity, RiskLevel};
//!
//! let results = analyze_complexity("./src", Some("python"), None)?;
//! for result in results.functions {
//! if result.risk_level == RiskLevel::High {
//! println!("High complexity: {} ({})", result.function_name, result.complexity);
//! }
//! }
//! ```
//!
//! # Cognitive Complexity Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_cognitive_complexity, CognitiveRiskLevel};
//!
//! let results = analyze_cognitive_complexity("./src", Some("python"), Some(10))?;
//! for func in &results.functions {
//! if func.risk_level == CognitiveRiskLevel::High {
//! println!("Hard to understand: {} (score: {})", func.function_name, func.complexity);
//! for contrib in &func.breakdown {
//! println!(" Line {}: {} (+{} base, +{} nesting)",
//! contrib.line, contrib.construct, contrib.base_increment, contrib.nesting_increment);
//! }
//! }
//! }
//! ```
//!
//! # Halstead Complexity Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_halstead, QualityLevel};
//!
//! let results = analyze_halstead("./src", Some("python"), false)?;
//! for func in &results.functions {
//! println!("{}: volume={:.1}, difficulty={:.1}, bugs={:.2}",
//! func.function_name, func.metrics.volume, func.metrics.difficulty, func.metrics.bugs);
//! }
//! println!("Total estimated bugs: {:.2}", results.stats.total_bugs);
//! ```
//!
//! # Lines of Code Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_loc, LOCMetrics};
//!
//! let results = analyze_loc("./src", Some("python"), None)?;
//! println!("Total SLOC: {}", results.stats.total_sloc);
//! println!("Code-to-comment ratio: {:.2}", results.stats.code_to_comment_ratio);
//! for lang in &results.by_language {
//! println!("{}: {} SLOC across {} files", lang.language, lang.metrics.source, lang.file_count);
//! }
//! ```
//!
//! # Nesting Depth Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_nesting, NestingDepthLevel};
//!
//! let results = analyze_nesting("./src", Some("python"), Some(5))?;
//! for func in &results.functions {
//! if func.risk_level == NestingDepthLevel::Severe {
//! println!("Deep nesting in {}: depth {} at line {}",
//! func.function_name, func.max_depth, func.deepest_line);
//! for suggestion in &func.suggestions {
//! println!(" - {}", suggestion);
//! }
//! }
//! }
//! ```
//!
//! # Function Size Metrics Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_function_size, SizeIssue};
//!
//! let results = analyze_function_size("./src", Some("python"), None)?;
//! for func in &results.violations {
//! println!("{} at {}:{} - {} issues:",
//! func.name, func.file.display(), func.line, func.issues.len());
//! for issue in &func.issues {
//! println!(" - {}", issue);
//! }
//! }
//! ```
//!
//! # Coupling Metrics Example
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_coupling, CouplingLevel};
//!
//! let results = analyze_coupling("./src", Some("python"), CouplingLevel::File)?;
//! for module in &results.modules {
//! println!("{}: Ca={}, Ce={}, I={:.2}, D={:.2}",
//! module.module, module.afferent, module.efferent,
//! module.instability, module.distance);
//! if module.is_in_zone_of_pain() {
//! println!(" WARNING: In Zone of Pain (stable, concrete - rigid)");
//! }
//! if module.distance > 0.5 {
//! println!(" WARNING: Far from main sequence!");
//! }
//! }
//! ```
//!
//! # Cohesion Metrics Example (LCOM)
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_cohesion, CohesionLevel};
//!
//! let results = analyze_cohesion("./src", Some("python"), Some(1))?;
//! for class in &results.classes {
//! println!("{}: LCOM3={}, LCOM4={}, methods={}, attributes={}",
//! class.class_name, class.lcom3, class.lcom4, class.methods, class.attributes);
//! if class.is_low_cohesion {
//! println!(" WARNING: Low cohesion detected!");
//! if let Some(suggestion) = &class.suggestion {
//! println!(" Suggestion: {}", suggestion);
//! }
//! for (i, component) in class.components.iter().enumerate() {
//! println!(" Component {}: {:?}", i + 1, component);
//! }
//! }
//! }
//! println!("Stats: {}/{} classes have low cohesion",
//! results.stats.low_cohesion_classes, results.stats.total_classes);
//! ```
//!
//! # Unified Metrics Report
//!
//! For a comprehensive analysis combining all metrics:
//!
//! ```ignore
//! use go_brrr::metrics::{analyze_all_metrics, MetricsConfig, QualityGate};
//!
//! let config = MetricsConfig::default();
//! let report = analyze_all_metrics("./src", Some("python"), &config)?;
//!
//! // Check quality gates for CI/CD
//! let gate = QualityGate::default();
//! let result = gate.check(&report);
//! if result.failed {
//! eprintln!("Quality gate failed: {} critical issues", result.critical_count);
//! std::process::exit(1);
//! }
//!
//! // Access unified function metrics
//! for func in &report.function_metrics {
//! println!("{}: CC={}, cognitive={}, MI={:.1}",
//! func.name, func.cyclomatic, func.cognitive, func.maintainability);
//! }
//! ```
// Re-export primary types for convenience
pub use ;
// Re-export LOC types
pub use ;
// Re-export nesting types
pub use ;
// Re-export function size types
pub use ;
// Re-export coupling types
pub use ;
// Re-export cohesion types
pub use ;
// Re-export unified metrics types
pub use ;