diff --git a/docs/YARA-X Config Guide.md b/docs/YARA-X Config Guide.md index fe281fdf..fda8b8e6 100644 --- a/docs/YARA-X Config Guide.md +++ b/docs/YARA-X Config Guide.md @@ -9,8 +9,8 @@ The `yr` command looks in `${HOME}/.yara-x.toml` when starting up. If that file does not exist the default values are used. An example `.yara-x.toml` file is below, with comments that explain each option. -The values for each option are the default values that are used if omit the -option. +The values for each option are the default values that are used if the option +is omitted. This is the definitive list of supported configuration options, and will be updated as more are added. @@ -139,8 +139,8 @@ rule.empty_line_after_section_header = false # # Note that alignment is done with spaces, regardless of rule.indent_spaces # setting. -meta.align_values = false +meta.align_values = true # Same as meta.align_values but applies to patterns. -patterns.align_values = false +patterns.align_values = true ``` \ No newline at end of file diff --git a/fmt/src/lib.rs b/fmt/src/lib.rs index 84c5a1a1..78769d5c 100644 --- a/fmt/src/lib.rs +++ b/fmt/src/lib.rs @@ -615,7 +615,6 @@ impl Formatter { | Keyword(b"strings") | Keyword(b"condition") ) && ctx.token(-1).is_not(*NEWLINE) - && ctx.token(-2).is_not(*NEWLINE) }, processor::actions::emptyline, ) diff --git a/fmt/src/testdata/config_tests/align_metadata_false.formatted b/fmt/src/testdata/config_tests/align_metadata_false.formatted new file mode 100644 index 00000000..02081673 --- /dev/null +++ b/fmt/src/testdata/config_tests/align_metadata_false.formatted @@ -0,0 +1,12 @@ +rule test { + meta: + a = "b" + long = "foo" + + strings: + $a = "b" + $axs = { 06 11 } + + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/align_patterns_false.formatted b/fmt/src/testdata/config_tests/align_patterns_false.formatted new file mode 100644 index 00000000..a1cc9a0b --- /dev/null +++ b/fmt/src/testdata/config_tests/align_patterns_false.formatted @@ -0,0 +1,12 @@ +rule test { + meta: + a = "b" + long = "foo" + + strings: + $a = "b" + $axs = { 06 11 } + + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/align_rule.unformatted b/fmt/src/testdata/config_tests/align_rule.unformatted new file mode 100644 index 00000000..9b7c98e7 --- /dev/null +++ b/fmt/src/testdata/config_tests/align_rule.unformatted @@ -0,0 +1 @@ +rule test{meta:a="b"long="foo"strings:$a="b"$axs={0611}condition:$a} \ No newline at end of file diff --git a/fmt/src/testdata/config_tests/empty_line_after_section_header_true.formatted b/fmt/src/testdata/config_tests/empty_line_after_section_header_true.formatted new file mode 100644 index 00000000..0015236d --- /dev/null +++ b/fmt/src/testdata/config_tests/empty_line_after_section_header_true.formatted @@ -0,0 +1,13 @@ +rule test { + meta: + + a = "b" + + strings: + + $a = "b" + + condition: + + $a +} diff --git a/fmt/src/testdata/config_tests/empty_line_before_section_header_false.formatted b/fmt/src/testdata/config_tests/empty_line_before_section_header_false.formatted new file mode 100644 index 00000000..1db4bbab --- /dev/null +++ b/fmt/src/testdata/config_tests/empty_line_before_section_header_false.formatted @@ -0,0 +1,8 @@ +rule test { + meta: + a = "b" + strings: + $a = "b" + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/generic_rule.unformatted b/fmt/src/testdata/config_tests/generic_rule.unformatted new file mode 100644 index 00000000..7e08e801 --- /dev/null +++ b/fmt/src/testdata/config_tests/generic_rule.unformatted @@ -0,0 +1,2 @@ + +rule test{meta:a="b"strings:$a="b"condition:$a} \ No newline at end of file diff --git a/fmt/src/testdata/config_tests/indent_section_contents_false.formatted b/fmt/src/testdata/config_tests/indent_section_contents_false.formatted new file mode 100644 index 00000000..941d7a8d --- /dev/null +++ b/fmt/src/testdata/config_tests/indent_section_contents_false.formatted @@ -0,0 +1,10 @@ +rule test { + meta: + a = "b" + + strings: + $a = "b" + + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/indent_section_headers_false.formatted b/fmt/src/testdata/config_tests/indent_section_headers_false.formatted new file mode 100644 index 00000000..6211547d --- /dev/null +++ b/fmt/src/testdata/config_tests/indent_section_headers_false.formatted @@ -0,0 +1,10 @@ +rule test { +meta: + a = "b" + +strings: + $a = "b" + +condition: + $a +} diff --git a/fmt/src/testdata/config_tests/indent_spaces_one.formatted b/fmt/src/testdata/config_tests/indent_spaces_one.formatted new file mode 100644 index 00000000..96640034 --- /dev/null +++ b/fmt/src/testdata/config_tests/indent_spaces_one.formatted @@ -0,0 +1,10 @@ +rule test { + meta: + a = "b" + + strings: + $a = "b" + + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/indent_spaces_zero.formatted b/fmt/src/testdata/config_tests/indent_spaces_zero.formatted new file mode 100644 index 00000000..364d7602 --- /dev/null +++ b/fmt/src/testdata/config_tests/indent_spaces_zero.formatted @@ -0,0 +1,10 @@ +rule test { + meta: + a = "b" + + strings: + $a = "b" + + condition: + $a +} diff --git a/fmt/src/testdata/config_tests/newline_before_curly_brace_true.formatted b/fmt/src/testdata/config_tests/newline_before_curly_brace_true.formatted new file mode 100644 index 00000000..38ef75ce --- /dev/null +++ b/fmt/src/testdata/config_tests/newline_before_curly_brace_true.formatted @@ -0,0 +1,11 @@ +rule test +{ + meta: + a = "b" + + strings: + $a = "b" + + condition: + $a +} diff --git a/fmt/src/testdata/test1.formatted b/fmt/src/testdata/default_tests/test1.formatted similarity index 100% rename from fmt/src/testdata/test1.formatted rename to fmt/src/testdata/default_tests/test1.formatted diff --git a/fmt/src/testdata/test1.unformatted b/fmt/src/testdata/default_tests/test1.unformatted similarity index 100% rename from fmt/src/testdata/test1.unformatted rename to fmt/src/testdata/default_tests/test1.unformatted diff --git a/fmt/src/testdata/test10.formatted b/fmt/src/testdata/default_tests/test10.formatted similarity index 100% rename from fmt/src/testdata/test10.formatted rename to fmt/src/testdata/default_tests/test10.formatted diff --git a/fmt/src/testdata/test10.unformatted b/fmt/src/testdata/default_tests/test10.unformatted similarity index 100% rename from fmt/src/testdata/test10.unformatted rename to fmt/src/testdata/default_tests/test10.unformatted diff --git a/fmt/src/testdata/test11.formatted b/fmt/src/testdata/default_tests/test11.formatted similarity index 100% rename from fmt/src/testdata/test11.formatted rename to fmt/src/testdata/default_tests/test11.formatted diff --git a/fmt/src/testdata/test11.unformatted b/fmt/src/testdata/default_tests/test11.unformatted similarity index 100% rename from fmt/src/testdata/test11.unformatted rename to fmt/src/testdata/default_tests/test11.unformatted diff --git a/fmt/src/testdata/test12.formatted b/fmt/src/testdata/default_tests/test12.formatted similarity index 100% rename from fmt/src/testdata/test12.formatted rename to fmt/src/testdata/default_tests/test12.formatted diff --git a/fmt/src/testdata/test12.unformatted b/fmt/src/testdata/default_tests/test12.unformatted similarity index 100% rename from fmt/src/testdata/test12.unformatted rename to fmt/src/testdata/default_tests/test12.unformatted diff --git a/fmt/src/testdata/test13.formatted b/fmt/src/testdata/default_tests/test13.formatted similarity index 100% rename from fmt/src/testdata/test13.formatted rename to fmt/src/testdata/default_tests/test13.formatted diff --git a/fmt/src/testdata/test13.unformatted b/fmt/src/testdata/default_tests/test13.unformatted similarity index 100% rename from fmt/src/testdata/test13.unformatted rename to fmt/src/testdata/default_tests/test13.unformatted diff --git a/fmt/src/testdata/test14.formatted b/fmt/src/testdata/default_tests/test14.formatted similarity index 100% rename from fmt/src/testdata/test14.formatted rename to fmt/src/testdata/default_tests/test14.formatted diff --git a/fmt/src/testdata/test14.unformatted b/fmt/src/testdata/default_tests/test14.unformatted similarity index 100% rename from fmt/src/testdata/test14.unformatted rename to fmt/src/testdata/default_tests/test14.unformatted diff --git a/fmt/src/testdata/test15.formatted b/fmt/src/testdata/default_tests/test15.formatted similarity index 100% rename from fmt/src/testdata/test15.formatted rename to fmt/src/testdata/default_tests/test15.formatted diff --git a/fmt/src/testdata/test15.unformatted b/fmt/src/testdata/default_tests/test15.unformatted similarity index 100% rename from fmt/src/testdata/test15.unformatted rename to fmt/src/testdata/default_tests/test15.unformatted diff --git a/fmt/src/testdata/test16.formatted b/fmt/src/testdata/default_tests/test16.formatted similarity index 100% rename from fmt/src/testdata/test16.formatted rename to fmt/src/testdata/default_tests/test16.formatted diff --git a/fmt/src/testdata/test16.unformatted b/fmt/src/testdata/default_tests/test16.unformatted similarity index 100% rename from fmt/src/testdata/test16.unformatted rename to fmt/src/testdata/default_tests/test16.unformatted diff --git a/fmt/src/testdata/test17.formatted b/fmt/src/testdata/default_tests/test17.formatted similarity index 100% rename from fmt/src/testdata/test17.formatted rename to fmt/src/testdata/default_tests/test17.formatted diff --git a/fmt/src/testdata/test17.unformatted b/fmt/src/testdata/default_tests/test17.unformatted similarity index 100% rename from fmt/src/testdata/test17.unformatted rename to fmt/src/testdata/default_tests/test17.unformatted diff --git a/fmt/src/testdata/test18.formatted b/fmt/src/testdata/default_tests/test18.formatted similarity index 100% rename from fmt/src/testdata/test18.formatted rename to fmt/src/testdata/default_tests/test18.formatted diff --git a/fmt/src/testdata/test18.unformatted b/fmt/src/testdata/default_tests/test18.unformatted similarity index 100% rename from fmt/src/testdata/test18.unformatted rename to fmt/src/testdata/default_tests/test18.unformatted diff --git a/fmt/src/testdata/test19.formatted b/fmt/src/testdata/default_tests/test19.formatted similarity index 100% rename from fmt/src/testdata/test19.formatted rename to fmt/src/testdata/default_tests/test19.formatted diff --git a/fmt/src/testdata/test19.unformatted b/fmt/src/testdata/default_tests/test19.unformatted similarity index 100% rename from fmt/src/testdata/test19.unformatted rename to fmt/src/testdata/default_tests/test19.unformatted diff --git a/fmt/src/testdata/test2.formatted b/fmt/src/testdata/default_tests/test2.formatted similarity index 100% rename from fmt/src/testdata/test2.formatted rename to fmt/src/testdata/default_tests/test2.formatted diff --git a/fmt/src/testdata/test2.unformatted b/fmt/src/testdata/default_tests/test2.unformatted similarity index 100% rename from fmt/src/testdata/test2.unformatted rename to fmt/src/testdata/default_tests/test2.unformatted diff --git a/fmt/src/testdata/test20.formatted b/fmt/src/testdata/default_tests/test20.formatted similarity index 100% rename from fmt/src/testdata/test20.formatted rename to fmt/src/testdata/default_tests/test20.formatted diff --git a/fmt/src/testdata/test20.unformatted b/fmt/src/testdata/default_tests/test20.unformatted similarity index 100% rename from fmt/src/testdata/test20.unformatted rename to fmt/src/testdata/default_tests/test20.unformatted diff --git a/fmt/src/testdata/test21.formatted b/fmt/src/testdata/default_tests/test21.formatted similarity index 100% rename from fmt/src/testdata/test21.formatted rename to fmt/src/testdata/default_tests/test21.formatted diff --git a/fmt/src/testdata/test21.unformatted b/fmt/src/testdata/default_tests/test21.unformatted similarity index 100% rename from fmt/src/testdata/test21.unformatted rename to fmt/src/testdata/default_tests/test21.unformatted diff --git a/fmt/src/testdata/test22.formatted b/fmt/src/testdata/default_tests/test22.formatted similarity index 100% rename from fmt/src/testdata/test22.formatted rename to fmt/src/testdata/default_tests/test22.formatted diff --git a/fmt/src/testdata/test22.unformatted b/fmt/src/testdata/default_tests/test22.unformatted similarity index 100% rename from fmt/src/testdata/test22.unformatted rename to fmt/src/testdata/default_tests/test22.unformatted diff --git a/fmt/src/testdata/test23.formatted b/fmt/src/testdata/default_tests/test23.formatted similarity index 100% rename from fmt/src/testdata/test23.formatted rename to fmt/src/testdata/default_tests/test23.formatted diff --git a/fmt/src/testdata/test23.unformatted b/fmt/src/testdata/default_tests/test23.unformatted similarity index 100% rename from fmt/src/testdata/test23.unformatted rename to fmt/src/testdata/default_tests/test23.unformatted diff --git a/fmt/src/testdata/test24.formatted b/fmt/src/testdata/default_tests/test24.formatted similarity index 100% rename from fmt/src/testdata/test24.formatted rename to fmt/src/testdata/default_tests/test24.formatted diff --git a/fmt/src/testdata/test24.unformatted b/fmt/src/testdata/default_tests/test24.unformatted similarity index 100% rename from fmt/src/testdata/test24.unformatted rename to fmt/src/testdata/default_tests/test24.unformatted diff --git a/fmt/src/testdata/test25.formatted b/fmt/src/testdata/default_tests/test25.formatted similarity index 100% rename from fmt/src/testdata/test25.formatted rename to fmt/src/testdata/default_tests/test25.formatted diff --git a/fmt/src/testdata/test25.unformatted b/fmt/src/testdata/default_tests/test25.unformatted similarity index 100% rename from fmt/src/testdata/test25.unformatted rename to fmt/src/testdata/default_tests/test25.unformatted diff --git a/fmt/src/testdata/test26.formatted b/fmt/src/testdata/default_tests/test26.formatted similarity index 100% rename from fmt/src/testdata/test26.formatted rename to fmt/src/testdata/default_tests/test26.formatted diff --git a/fmt/src/testdata/test26.unformatted b/fmt/src/testdata/default_tests/test26.unformatted similarity index 100% rename from fmt/src/testdata/test26.unformatted rename to fmt/src/testdata/default_tests/test26.unformatted diff --git a/fmt/src/testdata/test27.formatted b/fmt/src/testdata/default_tests/test27.formatted similarity index 100% rename from fmt/src/testdata/test27.formatted rename to fmt/src/testdata/default_tests/test27.formatted diff --git a/fmt/src/testdata/test27.unformatted b/fmt/src/testdata/default_tests/test27.unformatted similarity index 100% rename from fmt/src/testdata/test27.unformatted rename to fmt/src/testdata/default_tests/test27.unformatted diff --git a/fmt/src/testdata/test28.formatted b/fmt/src/testdata/default_tests/test28.formatted similarity index 100% rename from fmt/src/testdata/test28.formatted rename to fmt/src/testdata/default_tests/test28.formatted diff --git a/fmt/src/testdata/test28.unformatted b/fmt/src/testdata/default_tests/test28.unformatted similarity index 100% rename from fmt/src/testdata/test28.unformatted rename to fmt/src/testdata/default_tests/test28.unformatted diff --git a/fmt/src/testdata/test29.formatted b/fmt/src/testdata/default_tests/test29.formatted similarity index 100% rename from fmt/src/testdata/test29.formatted rename to fmt/src/testdata/default_tests/test29.formatted diff --git a/fmt/src/testdata/test29.unformatted b/fmt/src/testdata/default_tests/test29.unformatted similarity index 100% rename from fmt/src/testdata/test29.unformatted rename to fmt/src/testdata/default_tests/test29.unformatted diff --git a/fmt/src/testdata/test3.formatted b/fmt/src/testdata/default_tests/test3.formatted similarity index 100% rename from fmt/src/testdata/test3.formatted rename to fmt/src/testdata/default_tests/test3.formatted diff --git a/fmt/src/testdata/test3.unformatted b/fmt/src/testdata/default_tests/test3.unformatted similarity index 100% rename from fmt/src/testdata/test3.unformatted rename to fmt/src/testdata/default_tests/test3.unformatted diff --git a/fmt/src/testdata/test30.formatted b/fmt/src/testdata/default_tests/test30.formatted similarity index 100% rename from fmt/src/testdata/test30.formatted rename to fmt/src/testdata/default_tests/test30.formatted diff --git a/fmt/src/testdata/test30.unformatted b/fmt/src/testdata/default_tests/test30.unformatted similarity index 100% rename from fmt/src/testdata/test30.unformatted rename to fmt/src/testdata/default_tests/test30.unformatted diff --git a/fmt/src/testdata/test31.formatted b/fmt/src/testdata/default_tests/test31.formatted similarity index 100% rename from fmt/src/testdata/test31.formatted rename to fmt/src/testdata/default_tests/test31.formatted diff --git a/fmt/src/testdata/test31.unformatted b/fmt/src/testdata/default_tests/test31.unformatted similarity index 100% rename from fmt/src/testdata/test31.unformatted rename to fmt/src/testdata/default_tests/test31.unformatted diff --git a/fmt/src/testdata/test32.formatted b/fmt/src/testdata/default_tests/test32.formatted similarity index 100% rename from fmt/src/testdata/test32.formatted rename to fmt/src/testdata/default_tests/test32.formatted diff --git a/fmt/src/testdata/test32.unformatted b/fmt/src/testdata/default_tests/test32.unformatted similarity index 100% rename from fmt/src/testdata/test32.unformatted rename to fmt/src/testdata/default_tests/test32.unformatted diff --git a/fmt/src/testdata/test33.formatted b/fmt/src/testdata/default_tests/test33.formatted similarity index 100% rename from fmt/src/testdata/test33.formatted rename to fmt/src/testdata/default_tests/test33.formatted diff --git a/fmt/src/testdata/test33.unformatted b/fmt/src/testdata/default_tests/test33.unformatted similarity index 100% rename from fmt/src/testdata/test33.unformatted rename to fmt/src/testdata/default_tests/test33.unformatted diff --git a/fmt/src/testdata/test34.formatted b/fmt/src/testdata/default_tests/test34.formatted similarity index 100% rename from fmt/src/testdata/test34.formatted rename to fmt/src/testdata/default_tests/test34.formatted diff --git a/fmt/src/testdata/test34.unformatted b/fmt/src/testdata/default_tests/test34.unformatted similarity index 100% rename from fmt/src/testdata/test34.unformatted rename to fmt/src/testdata/default_tests/test34.unformatted diff --git a/fmt/src/testdata/test4.formatted b/fmt/src/testdata/default_tests/test4.formatted similarity index 100% rename from fmt/src/testdata/test4.formatted rename to fmt/src/testdata/default_tests/test4.formatted diff --git a/fmt/src/testdata/test4.unformatted b/fmt/src/testdata/default_tests/test4.unformatted similarity index 100% rename from fmt/src/testdata/test4.unformatted rename to fmt/src/testdata/default_tests/test4.unformatted diff --git a/fmt/src/testdata/test5.formatted b/fmt/src/testdata/default_tests/test5.formatted similarity index 100% rename from fmt/src/testdata/test5.formatted rename to fmt/src/testdata/default_tests/test5.formatted diff --git a/fmt/src/testdata/test5.unformatted b/fmt/src/testdata/default_tests/test5.unformatted similarity index 100% rename from fmt/src/testdata/test5.unformatted rename to fmt/src/testdata/default_tests/test5.unformatted diff --git a/fmt/src/testdata/test6.formatted b/fmt/src/testdata/default_tests/test6.formatted similarity index 100% rename from fmt/src/testdata/test6.formatted rename to fmt/src/testdata/default_tests/test6.formatted diff --git a/fmt/src/testdata/test6.unformatted b/fmt/src/testdata/default_tests/test6.unformatted similarity index 100% rename from fmt/src/testdata/test6.unformatted rename to fmt/src/testdata/default_tests/test6.unformatted diff --git a/fmt/src/testdata/test7.formatted b/fmt/src/testdata/default_tests/test7.formatted similarity index 100% rename from fmt/src/testdata/test7.formatted rename to fmt/src/testdata/default_tests/test7.formatted diff --git a/fmt/src/testdata/test7.unformatted b/fmt/src/testdata/default_tests/test7.unformatted similarity index 100% rename from fmt/src/testdata/test7.unformatted rename to fmt/src/testdata/default_tests/test7.unformatted diff --git a/fmt/src/testdata/test8.formatted b/fmt/src/testdata/default_tests/test8.formatted similarity index 100% rename from fmt/src/testdata/test8.formatted rename to fmt/src/testdata/default_tests/test8.formatted diff --git a/fmt/src/testdata/test8.unformatted b/fmt/src/testdata/default_tests/test8.unformatted similarity index 100% rename from fmt/src/testdata/test8.unformatted rename to fmt/src/testdata/default_tests/test8.unformatted diff --git a/fmt/src/testdata/test9.formatted b/fmt/src/testdata/default_tests/test9.formatted similarity index 100% rename from fmt/src/testdata/test9.formatted rename to fmt/src/testdata/default_tests/test9.formatted diff --git a/fmt/src/testdata/test9.unformatted b/fmt/src/testdata/default_tests/test9.unformatted similarity index 100% rename from fmt/src/testdata/test9.unformatted rename to fmt/src/testdata/default_tests/test9.unformatted diff --git a/fmt/src/tests.rs b/fmt/src/tests.rs index dc61bfb2..06b7a187 100644 --- a/fmt/src/tests.rs +++ b/fmt/src/tests.rs @@ -1,3 +1,4 @@ +use std::path::PathBuf; use std::{fs, str}; use pretty_assertions::assert_eq; @@ -39,11 +40,12 @@ fn spacer() { #[test] fn format() { - let files: Vec<_> = globwalk::glob("src/testdata/*.unformatted") - .unwrap() - .flatten() - .map(|entry| entry.into_path()) - .collect(); + let files: Vec<_> = + globwalk::glob("src/testdata/default_tests/*.unformatted") + .unwrap() + .flatten() + .map(|entry| entry.into_path()) + .collect(); files.into_par_iter().for_each(|path| { let mut mint = goldenfile::Mint::new("."); @@ -61,3 +63,75 @@ fn format() { } }); } + +#[test] +fn format_config_options() { + // Tuples for tests. First item is the formatter config to use. Second item + // is the unformatted test file. Third item is expected formatted file. + let tests = vec![ + ( + Formatter::new().indent_section_headers(false), + "generic_rule.unformatted", + "indent_section_headers_false.formatted", + ), + ( + Formatter::new().indent_section_contents(false), + "generic_rule.unformatted", + "indent_section_contents_false.formatted", + ), + ( + Formatter::new().indent_spaces(0), + "generic_rule.unformatted", + "indent_spaces_zero.formatted", + ), + ( + Formatter::new().indent_spaces(1), + "generic_rule.unformatted", + "indent_spaces_one.formatted", + ), + ( + Formatter::new().newline_before_curly_brace(true), + "generic_rule.unformatted", + "newline_before_curly_brace_true.formatted", + ), + ( + Formatter::new().empty_line_before_section_header(false), + "generic_rule.unformatted", + "empty_line_before_section_header_false.formatted", + ), + ( + Formatter::new().empty_line_after_section_header(true), + "generic_rule.unformatted", + "empty_line_after_section_header_true.formatted", + ), + ( + Formatter::new().align_metadata(false), + "align_rule.unformatted", + "align_metadata_false.formatted", + ), + ( + Formatter::new().align_patterns(false), + "align_rule.unformatted", + "align_patterns_false.formatted", + ), + ]; + + let base = PathBuf::from("src/testdata/config_tests/"); + for (formatter, unformatted, formatted) in tests { + let input = fs::read_to_string(base.join(unformatted)) + .expect("error reading unformatted file"); + let expected = fs::read_to_string(base.join(formatted)) + .expect("error reading formatted file"); + let mut output = Vec::new(); + + formatter + .format(input.as_bytes(), &mut output) + .expect("format failed"); + assert_eq!( + str::from_utf8(&output).unwrap(), + expected, + "Formatted file: {}", + formatted + ); + } +} diff --git a/fmt/src/trailing_spaces.rs b/fmt/src/trailing_spaces.rs index f87af3f6..8923421e 100644 --- a/fmt/src/trailing_spaces.rs +++ b/fmt/src/trailing_spaces.rs @@ -37,8 +37,8 @@ where for next in self.input.by_ref() { match next { // Keep pushing tokens into the buffer while they are - // whitespaces - Token::Whitespace => { + // whitespaces or tabs + Token::Whitespace | Token::Tab => { self.output_buffer.push_back(next); } // If we find a newline, discard all whitespaces previously