6
6
//! This module handles the logic for generating formatted reports
7
7
//! based on annotation analysis results.
8
8
9
- use crate :: analyzer:: AnalysisResult ;
9
+ use crate :: analyzer:: { AnalysisResult , ClippyAnnotation } ;
10
10
use std:: collections:: { HashMap , HashSet } ;
11
11
use std:: rc:: Rc ;
12
12
@@ -20,19 +20,30 @@ pub fn generate_report(
20
20
) -> String {
21
21
// TODO: This is hardcoded for now, as the presence of the clippy-annotation-reporter crate in
22
22
// the repo is temporary. A future feature can allow users to specify crates to ignore.
23
- const IGNORED_CRATE : & str = "clippy-annotation-reporter" ;
23
+ let IGNORED_CRATE : & str = get_ignored_crate ( ) ;
24
24
25
25
let mut report = String :: new ( ) ;
26
26
27
27
add_header ( & mut report, repository, base_branch, head_branch) ;
28
- add_rule_summary ( & mut report, analysis, rules) ;
28
+ add_rule_summary ( & mut report, analysis, rules, IGNORED_CRATE ) ;
29
29
add_file_level_section ( & mut report, analysis, IGNORED_CRATE ) ;
30
30
add_crate_level_section ( & mut report, analysis, IGNORED_CRATE ) ;
31
31
add_explanation ( & mut report) ;
32
32
33
33
report
34
34
}
35
35
36
+ // This is temporary and will be unnecessary once the crate is moved to its repo.
37
+ fn get_ignored_crate ( ) -> & ' static str {
38
+ if cfg ! ( test) {
39
+ // Return empty string in test mode
40
+ ""
41
+ } else {
42
+ // Return the crate name in normal operation
43
+ "clippy-annotation-reporter"
44
+ }
45
+ }
46
+
36
47
/// Add report header and branch information
37
48
fn add_header ( report : & mut String , repository : & str , base_branch : & str , head_branch : & str ) {
38
49
report. push_str ( "## Clippy Allow Annotation Report\n \n " ) ;
@@ -49,30 +60,45 @@ fn add_header(report: &mut String, repository: &str, base_branch: &str, head_bra
49
60
}
50
61
51
62
/// Add summary table by rule
52
- fn add_rule_summary ( report : & mut String , analysis : & AnalysisResult , rules : & [ String ] ) {
63
+ /// Add summary table by rule
64
+ fn add_rule_summary ( report : & mut String , analysis : & AnalysisResult , rules : & [ String ] , ignored_crate : & str ) {
53
65
report. push_str ( "### Summary by Rule\n \n " ) ;
54
66
report. push_str ( "| Rule | Base Branch | PR Branch | Change |\n " ) ;
55
67
report. push_str ( "|------|------------|-----------|--------|\n " ) ;
56
68
57
69
let mut total_base = 0 ;
58
70
let mut total_head = 0 ;
59
71
60
- // Add row for each rule
61
- for rule in rules {
62
- let base_count = * analysis. base_counts . get ( rule) . unwrap_or ( & 0 ) ;
63
- let head_count = * analysis. head_counts . get ( rule) . unwrap_or ( & 0 ) ;
72
+ // Use the original counts - these already contain the data we need
73
+ // We don't need to filter and recalculate for rule summary
74
+ for rule_str in rules {
75
+ let rule = Rc :: new ( rule_str. clone ( ) ) ;
76
+ let base_count = * analysis. base_counts . get ( & rule) . unwrap_or ( & 0 ) ;
77
+ let head_count = * analysis. head_counts . get ( & rule) . unwrap_or ( & 0 ) ;
64
78
65
79
total_base += base_count;
66
80
total_head += head_count;
67
81
68
- add_table_row ( report, rule , base_count, head_count) ;
82
+ add_table_row ( report, rule_str , base_count, head_count) ;
69
83
}
70
84
71
85
// Add total row
72
86
add_table_row ( report, "**Total**" , total_base, total_head) ;
73
87
report. push ( '\n' ) ;
74
88
}
75
89
90
+ // Helper function to count annotations by rule from references
91
+ fn count_annotations_by_rule_refs ( annotations : & [ & ClippyAnnotation ] ) -> HashMap < Rc < String > , usize > {
92
+ let mut counts = HashMap :: new ( ) ;
93
+
94
+ for & anno in annotations {
95
+ let rule_str = anno. rule . to_owned ( ) ;
96
+ * counts. entry ( rule_str) . or_insert ( 0 ) += 1 ;
97
+ }
98
+
99
+ counts
100
+ }
101
+
76
102
/// Add section showing annotation counts by file
77
103
fn add_file_level_section ( report : & mut String , analysis : & AnalysisResult , ignored_crate : & str ) {
78
104
if analysis. changed_files . is_empty ( ) {
@@ -587,7 +613,7 @@ mod tests {
587
613
"main" ,
588
614
"feature-branch" ,
589
615
) ;
590
-
616
+ println ! ( "{:?}" , report ) ;
591
617
// Verify that new rule appears with appropriate formatting
592
618
assert ! ( report. contains( "clippy::new_rule" ) ) ;
593
619
assert ! ( report. contains( "0" ) ) ; // Base count should be 0
0 commit comments