From eb20ba9f11c9af5d28ed14cb8df0203d22aee764 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 9 Nov 2020 19:35:37 -0600 Subject: [PATCH] refactor(report): Make Parse consistent with Typos --- crates/typos/src/checks.rs | 14 ++++++++------ crates/typos/src/report.rs | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/typos/src/checks.rs b/crates/typos/src/checks.rs index 20864a7..1cadf50 100644 --- a/crates/typos/src/checks.rs +++ b/crates/typos/src/checks.rs @@ -89,7 +89,7 @@ impl ParseIdentifiers { for part in path.components().filter_map(|c| c.as_os_str().to_str()) { let msg = report::Parse { - path, + context: report::PathContext { path }.into(), kind: report::ParseKind::Identifier, data: parser.parse(part).map(|i| i.token()).collect(), }; @@ -120,9 +120,10 @@ impl ParseIdentifiers { return Ok(typos_found); } - for line in buffer.lines() { + for (line_idx, line) in buffer.lines().enumerate() { + let line_num = line_idx + 1; let msg = report::Parse { - path, + context: report::FileContext { path, line_num }.into(), kind: report::ParseKind::Identifier, data: parser.parse_bytes(line).map(|i| i.token()).collect(), }; @@ -155,7 +156,7 @@ impl ParseWords { for part in path.components().filter_map(|c| c.as_os_str().to_str()) { let msg = report::Parse { - path, + context: report::PathContext { path }.into(), kind: report::ParseKind::Word, data: parser .parse(part) @@ -189,9 +190,10 @@ impl ParseWords { return Ok(typos_found); } - for line in buffer.lines() { + for (line_idx, line) in buffer.lines().enumerate() { + let line_num = line_idx + 1; let msg = report::Parse { - path, + context: report::FileContext { path, line_num }.into(), kind: report::ParseKind::Word, data: parser .parse_bytes(line) diff --git a/crates/typos/src/report.rs b/crates/typos/src/report.rs index 9131fc7..3a1c6d7 100644 --- a/crates/typos/src/report.rs +++ b/crates/typos/src/report.rs @@ -154,7 +154,7 @@ impl<'m> Default for File<'m> { #[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)] #[non_exhaustive] pub struct Parse<'m> { - pub path: &'m std::path::Path, + pub context: Context<'m>, pub kind: ParseKind, pub data: Vec<&'m str>, } @@ -162,7 +162,7 @@ pub struct Parse<'m> { impl<'m> Default for Parse<'m> { fn default() -> Self { Self { - path: std::path::Path::new("-"), + context: Context::None, kind: ParseKind::Identifier, data: vec![], }