From 628c011f77d0e68fa79fb8cfa7b656fe7100f39c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 10 Nov 2020 06:10:23 -0600 Subject: [PATCH] fix(report): Ensure json output is clean --- crates/typos/src/checks.rs | 16 ++++++++++++---- crates/typos/src/report.rs | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/typos/src/checks.rs b/crates/typos/src/checks.rs index 7b20b9b..374bebc 100644 --- a/crates/typos/src/checks.rs +++ b/crates/typos/src/checks.rs @@ -183,7 +183,9 @@ impl Check for ParseIdentifiers { kind: report::ParseKind::Identifier, data: parser.parse_str(buffer).map(|i| i.token()).collect(), }; - reporter.report(msg.into()); + if !msg.data.is_empty() { + reporter.report(msg.into()); + } Ok(typos_found) } @@ -202,7 +204,9 @@ impl Check for ParseIdentifiers { kind: report::ParseKind::Identifier, data: parser.parse_bytes(buffer).map(|i| i.token()).collect(), }; - reporter.report(msg.into()); + if !msg.data.is_empty() { + reporter.report(msg.into()); + } Ok(typos_found) } @@ -245,7 +249,9 @@ impl Check for ParseWords { .flat_map(|ident| ident.split().map(|i| i.token())) .collect(), }; - reporter.report(msg.into()); + if !msg.data.is_empty() { + reporter.report(msg.into()); + } Ok(typos_found) } @@ -267,7 +273,9 @@ impl Check for ParseWords { .flat_map(|ident| ident.split().map(|i| i.token())) .collect(), }; - reporter.report(msg.into()); + if !msg.data.is_empty() { + reporter.report(msg.into()); + } Ok(typos_found) } diff --git a/crates/typos/src/report.rs b/crates/typos/src/report.rs index 689fa63..a1386ca 100644 --- a/crates/typos/src/report.rs +++ b/crates/typos/src/report.rs @@ -64,6 +64,7 @@ pub struct BinaryFile<'m> { #[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)] #[non_exhaustive] pub struct Typo<'m> { + #[serde(flatten)] pub context: Context<'m>, #[serde(skip)] pub buffer: Cow<'m, [u8]>, @@ -85,6 +86,7 @@ impl<'m> Default for Typo<'m> { } #[derive(Clone, Debug, serde::Serialize, derive_more::From)] +#[serde(untagged)] #[non_exhaustive] pub enum Context<'m> { File(FileContext<'m>), @@ -139,6 +141,7 @@ impl<'m> Default for PathContext<'m> { } #[derive(Copy, Clone, Debug, serde::Serialize)] +#[serde(rename_all = "snake_case")] #[non_exhaustive] pub enum ParseKind { Identifier, @@ -168,6 +171,7 @@ impl<'m> Default for File<'m> { #[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)] #[non_exhaustive] pub struct Parse<'m> { + #[serde(flatten)] pub context: Context<'m>, pub kind: ParseKind, pub data: Vec<&'m str>,