fix: Improve accuracy of col_num field name

This commit is contained in:
Ed Page 2020-03-31 19:55:07 -05:00 committed by Ed Page
parent 7c41be2c1a
commit 8a619e7e39
2 changed files with 13 additions and 13 deletions

View file

@ -238,10 +238,10 @@ impl Checks {
if let Some(part) = path.file_name().and_then(|s| s.to_str()) {
for ident in parser.parse(part) {
if let Some(correction) = dictionary.correct_ident(ident) {
let col_num = ident.offset();
let byte_offset = ident.offset();
let msg = report::PathCorrection {
path,
col_num,
byte_offset,
typo: ident.token(),
correction,
non_exhaustive: (),
@ -251,10 +251,10 @@ impl Checks {
} else {
for word in ident.split() {
if let Some(correction) = dictionary.correct_word(word) {
let col_num = word.offset();
let byte_offset = word.offset();
let msg = report::PathCorrection {
path,
col_num,
byte_offset,
typo: word.token(),
correction,
non_exhaustive: (),
@ -299,12 +299,12 @@ impl Checks {
let line_num = line_idx + 1;
for ident in parser.parse_bytes(line) {
if let Some(correction) = dictionary.correct_ident(ident) {
let col_num = ident.offset();
let byte_offset = ident.offset();
let msg = report::Correction {
path,
line,
line_num,
col_num,
byte_offset,
typo: ident.token(),
correction,
non_exhaustive: (),
@ -314,12 +314,12 @@ impl Checks {
} else {
for word in ident.split() {
if let Some(correction) = dictionary.correct_word(word) {
let col_num = word.offset();
let byte_offset = word.offset();
let msg = report::Correction {
path,
line,
line_num,
col_num,
byte_offset,
typo: word.token(),
correction,
non_exhaustive: (),

View file

@ -30,7 +30,7 @@ pub struct Correction<'m> {
#[serde(skip)]
pub line: &'m [u8],
pub line_num: usize,
pub col_num: usize,
pub byte_offset: usize,
pub typo: &'m str,
pub correction: Cow<'m, str>,
#[serde(skip)]
@ -40,7 +40,7 @@ pub struct Correction<'m> {
#[derive(Clone, Debug, serde::Serialize)]
pub struct PathCorrection<'m> {
pub path: &'m std::path::Path,
pub col_num: usize,
pub byte_offset: usize,
pub typo: &'m str,
pub correction: Cow<'m, str>,
#[serde(skip)]
@ -129,7 +129,7 @@ impl Report for PrintBrief {
"{}:{}:{}: {} -> {}",
msg.path.display(),
msg.line_num,
msg.col_num,
msg.byte_offset,
msg.typo,
msg.correction
);
@ -197,7 +197,7 @@ fn print_long_correction(msg: Correction) {
let line_num = msg.line_num.to_string();
let line_indent: String = itertools::repeat_n(" ", line_num.len()).collect();
let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect();
let hl_indent: String = itertools::repeat_n(" ", msg.byte_offset).collect();
let hl: String = itertools::repeat_n("^", msg.typo.len()).collect();
let line = String::from_utf8_lossy(msg.line);
@ -217,7 +217,7 @@ fn print_long_correction(msg: Correction) {
" --> {}:{}:{}",
msg.path.display(),
msg.line_num,
msg.col_num
msg.byte_offset
)
.unwrap();
writeln!(handle, "{} |", line_indent).unwrap();