Combine error_on_line_overflow_comments/strings

1. Rename to error_on_unformatted_comments_or_strings
2. Set the option to false by default.
This commit is contained in:
Seiichi Uchida 2017-12-11 09:39:06 +09:00
parent 4d9226ffee
commit aea19d5e33
5 changed files with 21 additions and 32 deletions

View File

@ -682,10 +682,9 @@ create_config! {
disable_all_formatting: bool, false, false, "Don't reformat anything";
skip_children: bool, false, false, "Don't reformat out of line modules";
error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width";
error_on_line_overflow_comments: bool, true, false,
"Error if unable to get comments within max_width";
error_on_line_overflow_strings: bool, true, false,
"Error if unable to get string literals within max_width";
error_on_unformatted_comments_or_strings: bool, false, false,
"Error if unable to get comments or string literals within max_width, \
or they are left with trailing whitespaces";
report_todo: ReportTactic, ReportTactic::Never, false,
"Report all, none or unnumbered occurrences of TODO in source file comments";
report_fixme: ReportTactic, ReportTactic::Never, false,

View File

@ -119,12 +119,9 @@ impl FormattingError {
}
fn msg_suffix(&self) -> &str {
if self.is_comment {
"use `error_on_line_overflow_comments = false` to suppress \
the warning against comments\n"
} else if self.is_string {
"use `error_on_line_overflow_strings = false` to suppress \
the warning against string literals\n"
if self.is_comment || self.is_string {
"set `error_on_unformatted_comments_or_strings = false` to suppress \
the warning against comments or string literals\n"
} else {
""
}
@ -374,10 +371,8 @@ fn should_report_error(
is_string: bool,
error_kind: ErrorKind,
) -> bool {
let allow_error_report = if char_kind.is_comment() {
config.error_on_line_overflow_comments()
} else if is_string {
config.error_on_line_overflow_strings()
let allow_error_report = if char_kind.is_comment() || is_string {
config.error_on_unformatted_comments_or_strings()
} else {
true
};
@ -443,8 +438,7 @@ fn format_lines(
// Check for any line width errors we couldn't correct.
let error_kind = ErrorKind::LineOverflow(line_len, config.max_width());
if line_len > config.max_width()
&& !is_skipped_line(cur_line, skipped_range)
if line_len > config.max_width() && !is_skipped_line(cur_line, skipped_range)
&& should_report_error(config, kind, is_string, error_kind)
{
errors.push(FormattingError {

View File

@ -1,7 +0,0 @@
// rustfmt-error_on_line_overflow_comments: false
// Error on line overflow comment
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
fn main() {
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
}

View File

@ -1,9 +0,0 @@
// rustfmt-error_on_line_overflow_strings: false
// Suppress an error on line overflow strings.
fn main() {
let x = " ";
let a = "
";
}

View File

@ -0,0 +1,12 @@
// rustfmt-error_on_unformatted_comments_or_strings: false
// Error on line overflow comment or string literals.
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
fn main() {
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
let x = " ";
let a = "
";
}