11use super :: Formatter ;
22use code_guardian_core:: Match ;
3- use comfy_table:: { Cell , Table } ;
43
5- /// Formatter that outputs matches in a plain text table format.
6- /// Uses a table for structured display .
4+ /// Formatter that outputs matches in a simple text format.
5+ /// Each match is displayed as "file:line:column: pattern - message" .
76pub struct TextFormatter ;
87
98impl Formatter for TextFormatter {
@@ -12,21 +11,14 @@ impl Formatter for TextFormatter {
1211 return "No matches found." . to_string ( ) ;
1312 }
1413
15- let mut table = Table :: new ( ) ;
16- table
17- . set_header ( vec ! [ "File" , "Line" , "Column" , "Pattern" , "Message" ] ) ;
18-
14+ let mut output = String :: new ( ) ;
1915 for m in matches {
20- table. add_row ( vec ! [
21- Cell :: new( & m. file_path) ,
22- Cell :: new( m. line_number. to_string( ) ) ,
23- Cell :: new( m. column. to_string( ) ) ,
24- Cell :: new( & m. pattern) ,
25- Cell :: new( & m. message) ,
26- ] ) ;
16+ output. push_str ( & format ! (
17+ "{}:{}:{}: {} - {}\n " ,
18+ m. file_path, m. line_number, m. column, m. pattern, m. message
19+ ) ) ;
2720 }
28-
29- table. to_string ( )
21+ output. trim_end ( ) . to_string ( )
3022 }
3123}
3224
@@ -53,8 +45,8 @@ mod tests {
5345 message: "TODO comment" . to_string( ) ,
5446 } ] ;
5547 let output = formatter. format ( & matches) ;
56- assert ! ( output . contains ( "test.rs" ) ) ;
57- assert ! ( output. contains ( "TODO" ) ) ;
48+ let expected = "test.rs:1:1: TODO - TODO comment" ;
49+ assert_eq ! ( output, expected ) ;
5850 }
5951
6052 #[ test]
@@ -77,18 +69,8 @@ mod tests {
7769 } ,
7870 ] ;
7971 let output = formatter. format ( & matches) ;
80- // Check that the output contains the expected data
81- assert ! ( output. contains( "src/main.rs" ) ) ;
82- assert ! ( output. contains( "10" ) ) ;
83- assert ! ( output. contains( "5" ) ) ;
84- assert ! ( output. contains( "TODO" ) ) ;
85- assert ! ( output. contains( "Found a TODO" ) ) ;
86- assert ! ( output. contains( "src/lib.rs" ) ) ;
87- assert ! ( output. contains( "10" ) ) ;
88- assert ! ( output. contains( "1" ) ) ;
89- assert ! ( output. contains( "FIXME" ) ) ;
90- assert ! ( output. contains( "FIXME: temporary workaround" ) ) ;
91- // Ensure it's a table format
72+ let expected = "src/main.rs:10:5: TODO - Found a TODO\n src/lib.rs:10:1: FIXME - FIXME: temporary workaround" ;
73+ assert_eq ! ( output, expected) ;
9274 }
9375
9476 #[ test]
@@ -111,10 +93,8 @@ mod tests {
11193 } ,
11294 ] ;
11395 let output = formatter. format ( & matches) ;
114- assert ! ( output. contains( "test.rs" ) ) ;
115- assert ! ( output. contains( "test.js" ) ) ;
116- assert ! ( output. contains( "TODO" ) ) ;
117- assert ! ( output. contains( "FIXME" ) ) ;
96+ let expected = "test.rs:1:1: TODO - TODO\n test.js:2:3: FIXME - FIXME" ;
97+ assert_eq ! ( output, expected) ;
11898 }
11999}
120100
0 commit comments