fix(report): Ensure json output is clean

This commit is contained in:
Ed Page 2020-11-10 06:10:23 -06:00
parent e12cd8ed55
commit 628c011f77
2 changed files with 16 additions and 4 deletions

View file

@ -183,7 +183,9 @@ impl Check for ParseIdentifiers {
kind: report::ParseKind::Identifier, kind: report::ParseKind::Identifier,
data: parser.parse_str(buffer).map(|i| i.token()).collect(), 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) Ok(typos_found)
} }
@ -202,7 +204,9 @@ impl Check for ParseIdentifiers {
kind: report::ParseKind::Identifier, kind: report::ParseKind::Identifier,
data: parser.parse_bytes(buffer).map(|i| i.token()).collect(), 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) Ok(typos_found)
} }
@ -245,7 +249,9 @@ impl Check for ParseWords {
.flat_map(|ident| ident.split().map(|i| i.token())) .flat_map(|ident| ident.split().map(|i| i.token()))
.collect(), .collect(),
}; };
reporter.report(msg.into()); if !msg.data.is_empty() {
reporter.report(msg.into());
}
Ok(typos_found) Ok(typos_found)
} }
@ -267,7 +273,9 @@ impl Check for ParseWords {
.flat_map(|ident| ident.split().map(|i| i.token())) .flat_map(|ident| ident.split().map(|i| i.token()))
.collect(), .collect(),
}; };
reporter.report(msg.into()); if !msg.data.is_empty() {
reporter.report(msg.into());
}
Ok(typos_found) Ok(typos_found)
} }

View file

@ -64,6 +64,7 @@ pub struct BinaryFile<'m> {
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)] #[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
#[non_exhaustive] #[non_exhaustive]
pub struct Typo<'m> { pub struct Typo<'m> {
#[serde(flatten)]
pub context: Context<'m>, pub context: Context<'m>,
#[serde(skip)] #[serde(skip)]
pub buffer: Cow<'m, [u8]>, pub buffer: Cow<'m, [u8]>,
@ -85,6 +86,7 @@ impl<'m> Default for Typo<'m> {
} }
#[derive(Clone, Debug, serde::Serialize, derive_more::From)] #[derive(Clone, Debug, serde::Serialize, derive_more::From)]
#[serde(untagged)]
#[non_exhaustive] #[non_exhaustive]
pub enum Context<'m> { pub enum Context<'m> {
File(FileContext<'m>), File(FileContext<'m>),
@ -139,6 +141,7 @@ impl<'m> Default for PathContext<'m> {
} }
#[derive(Copy, Clone, Debug, serde::Serialize)] #[derive(Copy, Clone, Debug, serde::Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive] #[non_exhaustive]
pub enum ParseKind { pub enum ParseKind {
Identifier, Identifier,
@ -168,6 +171,7 @@ impl<'m> Default for File<'m> {
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)] #[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
#[non_exhaustive] #[non_exhaustive]
pub struct Parse<'m> { pub struct Parse<'m> {
#[serde(flatten)]
pub context: Context<'m>, pub context: Context<'m>,
pub kind: ParseKind, pub kind: ParseKind,
pub data: Vec<&'m str>, pub data: Vec<&'m str>,