Add error_on_line_overflow_comments config option
This commit is contained in:
parent
62689ef568
commit
e69a2aba18
3 changed files with 22 additions and 1 deletions
|
@ -501,6 +501,7 @@ create_config! {
|
||||||
via the --file-lines option";
|
via the --file-lines option";
|
||||||
max_width: usize, 100, "Maximum width of each line";
|
max_width: usize, 100, "Maximum width of each line";
|
||||||
error_on_line_overflow: bool, true, "Error if unable to get all lines within max_width";
|
error_on_line_overflow: bool, true, "Error if unable to get all lines within max_width";
|
||||||
|
error_on_line_overflow_comments: bool, true, "Error if unable to get comments within max_width";
|
||||||
tab_spaces: usize, 4, "Number of spaces per tab";
|
tab_spaces: usize, 4, "Number of spaces per tab";
|
||||||
fn_call_width: usize, 60,
|
fn_call_width: usize, 60,
|
||||||
"Maximum width of the args of a function call before falling back to vertical formatting";
|
"Maximum width of the args of a function call before falling back to vertical formatting";
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -599,6 +599,8 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||||
let mut newline_count = 0;
|
let mut newline_count = 0;
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
let mut issue_seeker = BadIssueSeeker::new(config.report_todo(), config.report_fixme());
|
let mut issue_seeker = BadIssueSeeker::new(config.report_todo(), config.report_fixme());
|
||||||
|
let mut prev_char: Option<char> = None;
|
||||||
|
let mut is_comment = false;
|
||||||
|
|
||||||
for (c, b) in text.chars() {
|
for (c, b) in text.chars() {
|
||||||
if c == '\r' {
|
if c == '\r' {
|
||||||
|
@ -626,7 +628,9 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for any line width errors we couldn't correct.
|
// Check for any line width errors we couldn't correct.
|
||||||
if config.error_on_line_overflow() && line_len > config.max_width() {
|
let report_error_on_line_overflow = config.error_on_line_overflow() &&
|
||||||
|
(config.error_on_line_overflow_comments() || !is_comment);
|
||||||
|
if report_error_on_line_overflow && line_len > config.max_width() {
|
||||||
errors.push(FormattingError {
|
errors.push(FormattingError {
|
||||||
line: cur_line,
|
line: cur_line,
|
||||||
kind: ErrorKind::LineOverflow(line_len, config.max_width()),
|
kind: ErrorKind::LineOverflow(line_len, config.max_width()),
|
||||||
|
@ -638,6 +642,8 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||||
cur_line += 1;
|
cur_line += 1;
|
||||||
newline_count += 1;
|
newline_count += 1;
|
||||||
last_wspace = None;
|
last_wspace = None;
|
||||||
|
prev_char = None;
|
||||||
|
is_comment = false;
|
||||||
} else {
|
} else {
|
||||||
newline_count = 0;
|
newline_count = 0;
|
||||||
line_len += 1;
|
line_len += 1;
|
||||||
|
@ -645,9 +651,16 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||||
if last_wspace.is_none() {
|
if last_wspace.is_none() {
|
||||||
last_wspace = Some(b);
|
last_wspace = Some(b);
|
||||||
}
|
}
|
||||||
|
} else if c == '/' {
|
||||||
|
match prev_char {
|
||||||
|
Some('/') => is_comment = true,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
last_wspace = None;
|
||||||
} else {
|
} else {
|
||||||
last_wspace = None;
|
last_wspace = None;
|
||||||
}
|
}
|
||||||
|
prev_char = Some(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
// rustfmt-error_on_line_overflow_comments: false
|
||||||
|
// Error on line overflow comment
|
||||||
|
|
||||||
|
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
fn main() {
|
||||||
|
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue