Skip to content

Commit 4bad05e

Browse files
committed
fix: change text formatter to simple text output for cross-platform compatibility
1 parent 6120e23 commit 4bad05e

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/output/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ thiserror = { workspace = true }
1212
anyhow = { workspace = true }
1313
chrono = { workspace = true }
1414
colored = { workspace = true }
15-
comfy-table = { workspace = true }
1615
csv = "1.1"
1716

1817
[dev-dependencies]

crates/output/src/formatters/text.rs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::Formatter;
22
use 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".
76
pub struct TextFormatter;
87

98
impl 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\nsrc/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\ntest.js:2:3: FIXME - FIXME";
97+
assert_eq!(output, expected);
11898
}
11999
}
120100

0 commit comments

Comments
 (0)