Skip to content

Commit 1fb172f

Browse files
committed
LineOverflow: Count tabs as tab_spaces when measuring line length for overflow
1 parent e0e3e22 commit 1fb172f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ fn format_lines(
463463
is_string = false;
464464
} else {
465465
newline_count = 0;
466-
line_len += 1;
466+
line_len += if c == '\t' { config.tab_spaces() } else { 1 };
467467
if c.is_whitespace() {
468468
if last_wspace.is_none() {
469469
last_wspace = Some(b);

tests/system.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ fn format_lines_errors_are_reported() {
261261
assert!(error_summary.has_formatting_errors());
262262
}
263263

264+
#[test]
265+
fn format_lines_errors_are_reported_with_tabs() {
266+
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
267+
let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier));
268+
let config = Config::from_toml("hard_tabs = true").unwrap();
269+
let (error_summary, _file_map, _report) =
270+
format_input::<io::Stdout>(input, &config, None).unwrap();
271+
assert!(error_summary.has_formatting_errors());
272+
}
273+
264274
// For each file, run rustfmt and collect the output.
265275
// Returns the number of files checked and the number of failures.
266276
fn check_files(files: Vec<PathBuf>) -> (Vec<FormatReport>, u32, u32) {

0 commit comments

Comments
 (0)