Respect file_lines within format_lines() function
This commit is contained in:
parent
75a13868da
commit
7c6479358b
@ -144,6 +144,20 @@ impl FileLines {
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains_line(&self, file_name: &str, line: usize) -> bool {
|
||||
let map = match self.0 {
|
||||
// `None` means "all lines in all files".
|
||||
None => return true,
|
||||
Some(ref map) => map,
|
||||
};
|
||||
|
||||
match canonicalize_path_string(file_name)
|
||||
.and_then(|canonical| map.get_vec(&canonical).ok_or(())) {
|
||||
Ok(ranges) => ranges.iter().any(|r| r.lo <= line && r.hi >= line),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// FileLines files iterator.
|
||||
|
42
src/lib.rs
42
src/lib.rs
@ -481,27 +481,35 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add warnings for bad todos/ fixmes
|
||||
if let Some(issue) = issue_seeker.inspect(c) {
|
||||
errors.push(FormattingError {
|
||||
line: cur_line,
|
||||
kind: ErrorKind::BadIssue(issue),
|
||||
});
|
||||
let format_line = config.file_lines.contains_line(name, cur_line as usize);
|
||||
|
||||
if format_line {
|
||||
// Add warnings for bad todos/ fixmes
|
||||
if let Some(issue) = issue_seeker.inspect(c) {
|
||||
errors.push(FormattingError {
|
||||
line: cur_line,
|
||||
kind: ErrorKind::BadIssue(issue),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if c == '\n' {
|
||||
// Check for (and record) trailing whitespace.
|
||||
if let Some(lw) = last_wspace {
|
||||
trims.push((cur_line, lw, b));
|
||||
line_len -= 1;
|
||||
}
|
||||
// Check for any line width errors we couldn't correct.
|
||||
if config.error_on_line_overflow && line_len > config.max_width {
|
||||
errors.push(FormattingError {
|
||||
line: cur_line,
|
||||
kind: ErrorKind::LineOverflow(line_len, config.max_width),
|
||||
});
|
||||
if format_line {
|
||||
// Check for (and record) trailing whitespace.
|
||||
if let Some(lw) = last_wspace {
|
||||
trims.push((cur_line, lw, b));
|
||||
line_len -= 1;
|
||||
}
|
||||
|
||||
// Check for any line width errors we couldn't correct.
|
||||
if config.error_on_line_overflow && line_len > config.max_width {
|
||||
errors.push(FormattingError {
|
||||
line: cur_line,
|
||||
kind: ErrorKind::LineOverflow(line_len, config.max_width),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
line_len = 0;
|
||||
cur_line += 1;
|
||||
newline_count += 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user