Make error_on_line_overflow false by default

And improve docs, the error message, etc.

I think false is the better default since such errors should only occur due to a bug in Rustfmt and therefore most users should not be notified of it happening (although to be clear, it might be a 'bug' which only occurs with pathological input and therefore we won't fix it). The error has proven to be confusing and annoying in the past.

Closes #1080
This commit is contained in:
Nick Cameron 2018-04-09 16:47:55 +12:00
parent 48e5bc1988
commit f14671131e
4 changed files with 17 additions and 12 deletions

View file

@ -579,9 +579,12 @@ Don't reformat anything
## `error_on_line_overflow`
Error if unable to get all lines within `max_width`, except for comments and string literals.
Error if Rustfmt is unable to get all lines within `max_width`, except for comments and string
literals. If this happens, then it is a bug in Rustfmt. You might be able to work around the bug by
refactoring your code to avoid long/complex expressions, usually by extracting a local variable or
using a shorter name.
- **Default value**: `true`
- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: No

View file

@ -134,7 +134,7 @@ create_config! {
disable_all_formatting: bool, false, false, "Don't reformat anything";
skip_children: bool, false, false, "Don't reformat out of line modules";
hide_parse_errors: bool, false, false, "Hide errors from the parser";
error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width";
error_on_line_overflow: bool, false, false, "Error if unable to get all lines within max_width";
error_on_unformatted: bool, false, false,
"Error if unable to get comments or string literals within max_width, \
or they are left with trailing whitespaces";

View file

@ -101,7 +101,7 @@ pub enum ErrorKind {
LineOverflow(usize, usize),
// Line ends in whitespace
TrailingWhitespace,
// TO-DO or FIX-ME item without an issue number
// TODO or FIXME item without an issue number
BadIssue(Issue),
// License check has failed
LicenseCheck,
@ -112,8 +112,8 @@ impl fmt::Display for ErrorKind {
match *self {
ErrorKind::LineOverflow(found, maximum) => write!(
fmt,
"line exceeded maximum width (maximum: {}, found: {})",
maximum, found
"line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})",
maximum, found,
),
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
@ -134,10 +134,9 @@ pub struct FormattingError {
impl FormattingError {
fn msg_prefix(&self) -> &str {
match self.kind {
ErrorKind::LineOverflow(..)
| ErrorKind::TrailingWhitespace
| ErrorKind::LicenseCheck => "error:",
ErrorKind::BadIssue(_) => "WARNING:",
ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "internal error:",
ErrorKind::LicenseCheck => "error:",
ErrorKind::BadIssue(_) => "warning:",
}
}

View file

@ -283,7 +283,8 @@ fn stdin_formatting_smoke_test() {
fn format_lines_errors_are_reported() {
let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
let input = Input::Text(format!("fn {}() {{}}", long_identifier));
let config = Config::default();
let mut config = Config::default();
config.set().error_on_line_overflow(true);
let (error_summary, _file_map, _report) =
format_input::<io::Stdout>(input, &config, None).unwrap();
assert!(error_summary.has_formatting_errors());
@ -293,7 +294,9 @@ fn format_lines_errors_are_reported() {
fn format_lines_errors_are_reported_with_tabs() {
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier));
let config = Config::from_toml("hard_tabs = true", Path::new("")).unwrap();
let mut config = Config::default();
config.set().error_on_line_overflow(true);
config.set().hard_tabs(true);
let (error_summary, _file_map, _report) =
format_input::<io::Stdout>(input, &config, None).unwrap();
assert!(error_summary.has_formatting_errors());