Skip to content

Commit

Permalink
feat: add fmt::Display impl to SyntaxErrorKind (#56)
Browse files Browse the repository at this point in the history
* move fmt impl to SyntaxErrorKind

* fmt

* empty format

---------

Co-authored-by: Pig Fang <[email protected]>
  • Loading branch information
bartlomieju and g-plane authored Sep 25, 2024
1 parent f404d6c commit 2b8ecc2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions markup_fmt/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub enum SyntaxErrorKind {
ExpectVueDirective,
}

impl fmt::Display for SyntaxError {
impl fmt::Display for SyntaxErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let reason: Cow<_> = match self.kind {
let reason: Cow<_> = match self {
SyntaxErrorKind::ExpectAngularFor => "expected Angular `@for`".into(),
SyntaxErrorKind::ExpectAngularIf => "expected Angular `@if`".into(),
SyntaxErrorKind::ExpectAngularLet => "expected Angular `@let`".into(),
Expand Down Expand Up @@ -92,10 +92,16 @@ impl fmt::Display for SyntaxError {
SyntaxErrorKind::ExpectVueDirective => "expected Vue directive".into(),
};

write!(f, "{reason}")
}
}

impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"syntax error '{reason}' at line {}, column {}",
self.line, self.column
"syntax error '{}' at line {}, column {}",
self.kind, self.line, self.column
)
}
}
Expand Down

0 comments on commit 2b8ecc2

Please sign in to comment.