Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't bail out of formatting code blocks if lines are >100 chars #4339

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/formatting/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,6 @@ pub(crate) fn format_code_block(code_snippet: &str, config: &Config) -> Option<F
}
let trimmed_line = if !is_indented {
line
} else if line.len() > config.max_width() {
// If there are lines that are larger than max width, we cannot tell
// whether we have succeeded but have some comments or strings that
// are too long, or we have failed to format code block. We will be
// conservative and just return `None` in this case.
return None;
} else if line.len() > indent_str.len() {
// Make sure that the line has leading whitespaces.
if line.starts_with(indent_str.as_ref()) {
Expand Down Expand Up @@ -885,13 +879,6 @@ mod test {
assert!(test_format_inner(format_snippet, snippet, expected));
}

#[test]
fn test_format_code_block_fail() {
#[rustfmt::skip]
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
assert!(format_code_block(code_block, &Config::default()).is_none());
}

#[test]
fn test_format_code_block() {
// simple code block
Expand Down Expand Up @@ -942,5 +929,11 @@ false,
)
};";
assert!(test_format_inner(format_code_block, code_block, expected));

#[rustfmt::skip]
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
#[rustfmt::skip]
let expected = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
assert!(test_format_inner(format_code_block, code_block, expected));
}
}
10 changes: 10 additions & 0 deletions tests/target/issue-4325.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
macro_rules! bad {
() => {
macro_rules! inner {
() => {
// This needs to have a width of over 100 characters to trigger the issue 12345678901
("a", "B")
};
}
};
}