Skip to content

Commit

Permalink
refactor(diagnostic): change how diagnostic codes are rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 29, 2024
1 parent fdef8ae commit 00ba188
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 7 additions & 2 deletions crates/oxc_diagnostics/src/graphic_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl GraphicalReportHandler {
f: &mut impl fmt::Write,
diagnostic: &(dyn Diagnostic),
) -> fmt::Result {
self.render_header(f, diagnostic)?;
// self.render_header(f, diagnostic)?;
writeln!(f)?;
self.render_causes(f, diagnostic)?;
let src = diagnostic.source_code();
Expand Down Expand Up @@ -271,7 +271,12 @@ impl GraphicalReportHandler {
opts = opts.word_splitter(word_splitter);
}

let title = format!("{}", diagnostic.to_string().style(severity_style));
let title = if let Some(code) = diagnostic.code() {
format!("{code}: {diagnostic}")
} else {
diagnostic.to_string()
};
let title = format!("{}", title.style(severity_style));
let title = textwrap::fill(&title, opts);
writeln!(f, "{}", title)?;

Expand Down
6 changes: 1 addition & 5 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ pub struct OxcDiagnosticInner {

impl fmt::Display for OxcDiagnostic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
if self.code.is_some() {
write!(f, "{}: ", &self.code)?;
}
write!(f, "{}", &self.message)
}
}
Expand All @@ -102,8 +99,7 @@ impl Diagnostic for OxcDiagnostic {
}

fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
// self.code.is_some().then(|| Box::new(&self.code) as Box<dyn Display>)
None
self.code.is_some().then(|| Box::new(&self.code) as Box<dyn Display>)
}
}

Expand Down
10 changes: 6 additions & 4 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,9 @@ failed to resolve query: failed to parse the rest of input: ...''


* class/accessor-allowDeclareFields-false/input.ts
x TS(18010): An accessibility modifier cannot be used with a private
| identifier.
TS(18010)

x An accessibility modifier cannot be used with a private identifier.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/input.ts:8:3]
7 | abstract accessor prop6: number;
8 | private accessor #p: any;
Expand All @@ -2157,8 +2158,9 @@ failed to resolve query: failed to parse the rest of input: ...''


* class/accessor-allowDeclareFields-true/input.ts
x TS(18010): An accessibility modifier cannot be used with a private
| identifier.
TS(18010)

x An accessibility modifier cannot be used with a private identifier.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/input.ts:8:3]
7 | abstract accessor prop6: number;
8 | private accessor #p: any;
Expand Down

0 comments on commit 00ba188

Please sign in to comment.