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:
parent
48e5bc1988
commit
f14671131e
4 changed files with 17 additions and 12 deletions
|
|
@ -579,9 +579,12 @@ Don't reformat anything
|
||||||
|
|
||||||
## `error_on_line_overflow`
|
## `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`
|
- **Possible values**: `true`, `false`
|
||||||
- **Stable**: No
|
- **Stable**: No
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ create_config! {
|
||||||
disable_all_formatting: bool, false, false, "Don't reformat anything";
|
disable_all_formatting: bool, false, false, "Don't reformat anything";
|
||||||
skip_children: bool, false, false, "Don't reformat out of line modules";
|
skip_children: bool, false, false, "Don't reformat out of line modules";
|
||||||
hide_parse_errors: bool, false, false, "Hide errors from the parser";
|
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_on_unformatted: bool, false, false,
|
||||||
"Error if unable to get comments or string literals within max_width, \
|
"Error if unable to get comments or string literals within max_width, \
|
||||||
or they are left with trailing whitespaces";
|
or they are left with trailing whitespaces";
|
||||||
|
|
|
||||||
13
src/lib.rs
13
src/lib.rs
|
|
@ -101,7 +101,7 @@ pub enum ErrorKind {
|
||||||
LineOverflow(usize, usize),
|
LineOverflow(usize, usize),
|
||||||
// Line ends in whitespace
|
// Line ends in whitespace
|
||||||
TrailingWhitespace,
|
TrailingWhitespace,
|
||||||
// TO-DO or FIX-ME item without an issue number
|
// TODO or FIXME item without an issue number
|
||||||
BadIssue(Issue),
|
BadIssue(Issue),
|
||||||
// License check has failed
|
// License check has failed
|
||||||
LicenseCheck,
|
LicenseCheck,
|
||||||
|
|
@ -112,8 +112,8 @@ impl fmt::Display for ErrorKind {
|
||||||
match *self {
|
match *self {
|
||||||
ErrorKind::LineOverflow(found, maximum) => write!(
|
ErrorKind::LineOverflow(found, maximum) => write!(
|
||||||
fmt,
|
fmt,
|
||||||
"line exceeded maximum width (maximum: {}, found: {})",
|
"line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})",
|
||||||
maximum, found
|
maximum, found,
|
||||||
),
|
),
|
||||||
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
|
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
|
||||||
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
|
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
|
||||||
|
|
@ -134,10 +134,9 @@ pub struct FormattingError {
|
||||||
impl FormattingError {
|
impl FormattingError {
|
||||||
fn msg_prefix(&self) -> &str {
|
fn msg_prefix(&self) -> &str {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
ErrorKind::LineOverflow(..)
|
ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "internal error:",
|
||||||
| ErrorKind::TrailingWhitespace
|
ErrorKind::LicenseCheck => "error:",
|
||||||
| ErrorKind::LicenseCheck => "error:",
|
ErrorKind::BadIssue(_) => "warning:",
|
||||||
ErrorKind::BadIssue(_) => "WARNING:",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,8 @@ fn stdin_formatting_smoke_test() {
|
||||||
fn format_lines_errors_are_reported() {
|
fn format_lines_errors_are_reported() {
|
||||||
let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
|
let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
|
||||||
let input = Input::Text(format!("fn {}() {{}}", long_identifier));
|
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) =
|
let (error_summary, _file_map, _report) =
|
||||||
format_input::<io::Stdout>(input, &config, None).unwrap();
|
format_input::<io::Stdout>(input, &config, None).unwrap();
|
||||||
assert!(error_summary.has_formatting_errors());
|
assert!(error_summary.has_formatting_errors());
|
||||||
|
|
@ -293,7 +294,9 @@ fn format_lines_errors_are_reported() {
|
||||||
fn format_lines_errors_are_reported_with_tabs() {
|
fn format_lines_errors_are_reported_with_tabs() {
|
||||||
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
|
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
|
||||||
let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier));
|
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) =
|
let (error_summary, _file_map, _report) =
|
||||||
format_input::<io::Stdout>(input, &config, None).unwrap();
|
format_input::<io::Stdout>(input, &config, None).unwrap();
|
||||||
assert!(error_summary.has_formatting_errors());
|
assert!(error_summary.has_formatting_errors());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue