Skip to content

Commit ed05be4

Browse files
refactor: remove --json format for tracing
BREAKING CHANGE: remove json format for tracing
1 parent 9a60d40 commit ed05be4

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

crates/cli/src/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<P: Printer> Worker for RunWithInferredLang<P> {
190190
}
191191
printer.after_print()?;
192192
// TODO: better handle output format
193-
if let Some(trace) = self.trace.print(self.arg.output.json.is_some()) {
193+
if let Some(trace) = self.trace.print() {
194194
eprintln!("{}", trace);
195195
}
196196
Ok(())
@@ -267,7 +267,7 @@ impl<P: Printer> Worker for RunWithSpecificLang<P> {
267267
has_matches = true;
268268
}
269269
printer.after_print()?;
270-
if let Some(stats) = self.stats.print(self.arg.output.json.is_some()) {
270+
if let Some(stats) = self.stats.print() {
271271
eprintln!("{}", stats);
272272
}
273273
if !has_matches && self.pattern.has_error() {

crates/cli/src/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<P: Printer> Worker for ScanWithConfig<P> {
177177
)?;
178178
}
179179
self.printer.after_print()?;
180-
if let Some(trace) = self.trace.print(self.arg.output.json.is_some()) {
180+
if let Some(trace) = self.trace.print() {
181181
eprintln!("{}", trace);
182182
}
183183
if error_count > 0 {

crates/cli/src/utils/tracing.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,13 @@ pub struct TraceInfo<T> {
8686
#[serde(flatten)]
8787
pub inner: T,
8888
}
89+
8990
impl TraceInfo<()> {
9091
// TODO: support more format?
91-
pub fn print(&self, is_json: bool) -> Option<String> {
92+
pub fn print(&self) -> Option<String> {
9293
match self.level {
9394
Tracing::Nothing => None,
94-
Tracing::Summary | Tracing::Entity => {
95-
if is_json {
96-
Some(serde_json::to_string(self).ok()?)
97-
} else {
98-
Some(self.file_trace.print())
99-
}
100-
}
95+
Tracing::Summary | Tracing::Entity => Some(self.file_trace.print()),
10196
}
10297
}
10398

@@ -112,20 +107,14 @@ impl TraceInfo<()> {
112107

113108
impl TraceInfo<RuleTrace> {
114109
// TODO: support more format?
115-
pub fn print(&self, is_json: bool) -> Option<String> {
110+
pub fn print(&self) -> Option<String> {
116111
match self.level {
117112
Tracing::Nothing => None,
118-
Tracing::Summary | Tracing::Entity => {
119-
if is_json {
120-
Some(serde_json::to_string(self).ok()?)
121-
} else {
122-
Some(format!(
123-
"{}\n{}",
124-
self.file_trace.print(),
125-
self.inner.print()
126-
))
127-
}
128-
}
113+
Tracing::Summary | Tracing::Entity => Some(format!(
114+
"{}\n{}",
115+
self.file_trace.print(),
116+
self.inner.print()
117+
)),
129118
}
130119
}
131120
pub fn print_file(
@@ -181,7 +170,7 @@ mod test {
181170
run_trace.file_trace.files_skipped.load(Ordering::Relaxed),
182171
0
183172
);
184-
let printed = run_trace.print(false).expect("should have output");
173+
let printed = run_trace.print().expect("should have output");
185174
assert_eq!(printed, "Files scanned: 0, Files skipped: 0");
186175

187176
let rule_stats = RuleTrace {
@@ -200,7 +189,7 @@ mod test {
200189
);
201190
assert_eq!(scan_trace.inner.effective_rule_count, 10);
202191
assert_eq!(scan_trace.inner.skipped_rule_count, 2);
203-
let printed = scan_trace.print(false).expect("should have output");
192+
let printed = scan_trace.print().expect("should have output");
204193
assert_eq!(
205194
printed,
206195
"Files scanned: 0, Files skipped: 0\nEffective rules: 10, Skipped rules: 2"
@@ -212,7 +201,7 @@ mod test {
212201
let tracing = Tracing::Nothing;
213202
let run_trace = tracing.run_trace();
214203
assert_eq!(run_trace.level, Tracing::Nothing);
215-
let printed = run_trace.print(false);
204+
let printed = run_trace.print();
216205
assert!(printed.is_none());
217206
}
218207
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy