Skip to content

Commit

Permalink
Added logging for long verbatim lines
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed May 19, 2024
1 parent 3a414ac commit df2a786
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 0 additions & 2 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
** Only print ignore warnings once
** Off by one in linums?
* Logging
** Store all logs on the fly in a vector
** Print them all at the end in an intelligent way
** Avoid panics to make sure we always reach the end
2 changes: 1 addition & 1 deletion src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn apply_indent(
Some(linum),
Some(line.to_string()),
format!(
"Indent: actual = {}, visual = {}.",
"Indent: actual = {}, visual = {}:",
indent.actual, indent.visual
),
);
Expand Down
45 changes: 32 additions & 13 deletions src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use log::Level::{Error, Info};

const WRAP: usize = 80;

// TODO add warning about long verbatim lines

pub fn needs_wrap(file: &str) -> bool {
file.lines().any(|l| l.len() > WRAP)
}
Expand Down Expand Up @@ -80,15 +78,15 @@ fn wrap_line(
}
None => {
can_wrap = false;
record_log(
logs,
Error,
pass,
filename.to_string(),
Some(linum),
Some(line.to_string()),
"Line cannot be wrapped.".to_string(),
);
//record_log(
//logs,
//Error,
//pass,
//filename.to_string(),
//Some(linum),
//Some(line.to_string()),
//"Line cannot be wrapped.".to_string(),
//);
}
}
}
Expand All @@ -115,7 +113,6 @@ pub fn wrap(
);
}
let mut new_file = "".to_string();
let mut new_line: String;
let mut verbatim_count = 0;
let mut ignore = Ignore::new();
for (linum, line) in file.lines().enumerate() {
Expand All @@ -125,10 +122,32 @@ pub fn wrap(
ignore = get_ignore(line, linum, ignore, filename, logs, pass, false);
if line_needs_wrap(line) && verbatim_count == 0 && !is_ignored(&ignore)
{
new_line = wrap_line(line, linum, args, logs, pass, filename);
let new_line = wrap_line(line, linum, args, logs, pass, filename);
new_file.push_str(&new_line);
if line_needs_wrap(&new_line) && !is_ignored(&ignore) {
record_log(
logs,
Error,
pass,
filename.to_string(),
Some(linum),
Some(new_line),
"Line cannot be wrapped:".to_string(),
);
}
} else {
new_file.push_str(line);
if line_needs_wrap(line) && !is_ignored(&ignore) {
record_log(
logs,
Error,
pass,
filename.to_string(),
Some(linum),
Some(line.to_string()),
"Line cannot be wrapped:".to_string(),
);
}
}
new_file.push('\n');
if RE_VERBATIM_BEGIN.is_match(line) {
Expand Down

0 comments on commit df2a786

Please sign in to comment.