Merge pull request #1325 from C4K3/master
Add error_on_line_overflow option
This commit is contained in:
commit
db10a0b9b2
27 changed files with 36 additions and 7 deletions
|
@ -333,6 +333,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";
|
||||||
ideal_width: usize, 80, "Ideal width of each line";
|
ideal_width: usize, 80, "Ideal width of each line";
|
||||||
|
error_on_line_overflow: bool, true, "Error if unable to get all lines 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";
|
||||||
|
|
|
@ -489,7 +489,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
|
||||||
line_len -= b - lw;
|
line_len -= b - lw;
|
||||||
}
|
}
|
||||||
// Check for any line width errors we couldn't correct.
|
// Check for any line width errors we couldn't correct.
|
||||||
if line_len > config.max_width {
|
if config.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),
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test() {
|
||||||
* amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis
|
* amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis
|
||||||
* felis, pulvinar a semper sed, adipiscing id dolor. */
|
* felis, pulvinar a semper sed, adipiscing id dolor. */
|
||||||
|
|
||||||
// Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split
|
// Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split
|
||||||
|
|
||||||
// println!("{:?}", rewrite_comment(subslice,
|
// println!("{:?}", rewrite_comment(subslice,
|
||||||
// false,
|
// false,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Enums test
|
// Enums test
|
||||||
|
|
||||||
#[atrr]
|
#[atrr]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[4,8]},{"file":"tests/source/file-lines-3.rs","range":[10,15]}]
|
// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[5,9]},{"file":"tests/source/file-lines-3.rs","range":[11,16]}]
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn floaters() {
|
fn floaters() {
|
||||||
let x = Foo {
|
let x = Foo {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// rustfmt-single_line_if_else_max_width: 0
|
// rustfmt-single_line_if_else_max_width: 0
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-hard_tabs: true
|
// rustfmt-hard_tabs: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Bar;
|
let x = Bar;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Imports.
|
// Imports.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
mod client {
|
mod client {
|
||||||
impl Client {
|
impl Client {
|
||||||
fn test(self) -> Result<()> {
|
fn test(self) -> Result<()> {
|
||||||
|
@ -10,7 +12,7 @@ mod client {
|
||||||
let next_state = match self.state {
|
let next_state = match self.state {
|
||||||
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
|
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
|
||||||
// The pattern cannot be formatted in a way that the match stays
|
// The pattern cannot be formatted in a way that the match stays
|
||||||
// within the column limit. The rewrite should therefore be
|
// within the column limit. The rewrite should therefore be
|
||||||
// skipped.
|
// skipped.
|
||||||
let x = dont . reformat . meeee();
|
let x = dont . reformat . meeee();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-force_format_strings: true
|
// rustfmt-force_format_strings: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Long string literals
|
// Long string literals
|
||||||
|
|
||||||
fn main() -> &'static str {
|
fn main() -> &'static str {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-format_strings: true
|
// rustfmt-format_strings: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:Likethisssssssssssss");
|
println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:Likethisssssssssssss");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-struct_lit_style: Visual
|
// rustfmt-struct_lit_style: Visual
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-struct_lit_style: Visual
|
// rustfmt-struct_lit_style: Visual
|
||||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
/// A Doc comment
|
/// A Doc comment
|
||||||
#[AnAttribute]
|
#[AnAttribute]
|
||||||
|
|
|
@ -179,6 +179,10 @@ fn check_files<I>(files: I) -> (Vec<FormatReport>, u32, u32)
|
||||||
println!("Testing '{}'...", file_name);
|
println!("Testing '{}'...", file_name);
|
||||||
|
|
||||||
match idempotent_check(file_name) {
|
match idempotent_check(file_name) {
|
||||||
|
Ok(ref report) if report.has_warnings() => {
|
||||||
|
print!("{}", report);
|
||||||
|
fails += 1;
|
||||||
|
}
|
||||||
Ok(report) => reports.push(report),
|
Ok(report) => reports.push(report),
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
print_mismatches(msg);
|
print_mismatches(msg);
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test() {
|
||||||
* amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis
|
* amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis
|
||||||
* felis, pulvinar a semper sed, adipiscing id dolor. */
|
* felis, pulvinar a semper sed, adipiscing id dolor. */
|
||||||
|
|
||||||
// Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split
|
// Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split
|
||||||
|
|
||||||
// println!("{:?}", rewrite_comment(subslice,
|
// println!("{:?}", rewrite_comment(subslice,
|
||||||
// false,
|
// false,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Enums test
|
// Enums test
|
||||||
|
|
||||||
#[atrr]
|
#[atrr]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[4,8]},{"file":"tests/source/file-lines-3.rs","range":[10,15]}]
|
// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[5,9]},{"file":"tests/source/file-lines-3.rs","range":[11,16]}]
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn floaters() {
|
fn floaters() {
|
||||||
let x = Foo {
|
let x = Foo {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// rustfmt-single_line_if_else_max_width: 0
|
// rustfmt-single_line_if_else_max_width: 0
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-hard_tabs: true
|
// rustfmt-hard_tabs: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Bar;
|
let x = Bar;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Imports.
|
// Imports.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
mod client {
|
mod client {
|
||||||
impl Client {
|
impl Client {
|
||||||
fn test(self) -> Result<()> {
|
fn test(self) -> Result<()> {
|
||||||
|
@ -10,7 +12,7 @@ mod client {
|
||||||
let next_state = match self.state {
|
let next_state = match self.state {
|
||||||
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
|
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
|
||||||
// The pattern cannot be formatted in a way that the match stays
|
// The pattern cannot be formatted in a way that the match stays
|
||||||
// within the column limit. The rewrite should therefore be
|
// within the column limit. The rewrite should therefore be
|
||||||
// skipped.
|
// skipped.
|
||||||
let x = dont . reformat . meeee();
|
let x = dont . reformat . meeee();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-force_format_strings: true
|
// rustfmt-force_format_strings: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Long string literals
|
// Long string literals
|
||||||
|
|
||||||
fn main() -> &'static str {
|
fn main() -> &'static str {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// rustfmt-format_strings: true
|
// rustfmt-format_strings: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:\
|
println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:\
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-struct_lit_style: Visual
|
// rustfmt-struct_lit_style: Visual
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
// rustfmt-struct_lit_style: Visual
|
// rustfmt-struct_lit_style: Visual
|
||||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
// Struct literal expressions.
|
// Struct literal expressions.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// rustfmt-normalize_comments: true
|
// rustfmt-normalize_comments: true
|
||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-error_on_line_overflow: false
|
||||||
|
|
||||||
/// A Doc comment
|
/// A Doc comment
|
||||||
#[AnAttribute]
|
#[AnAttribute]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue