From b7d61254a7c2b5fa9a03acc6b91445e72d7ee280 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 10 Nov 2015 08:03:01 +1300 Subject: [PATCH] Option to disable line breaking in comments Set to false by default for now, since we are having a lot of problems with comments. We should set to true once we have a better algorithm. --- src/comment.rs | 5 +++-- src/config.rs | 2 +- tests/source/attrib.rs | 1 + tests/source/comment.rs | 2 ++ tests/source/comment2.rs | 2 ++ tests/source/comment3.rs | 2 ++ tests/source/enum.rs | 1 + tests/source/expr.rs | 1 + tests/source/hard-tabs.rs | 1 + tests/source/multiple.rs | 1 + tests/source/struct_lits.rs | 1 + tests/source/struct_lits_multiline.rs | 1 + tests/source/struct_lits_visual.rs | 1 + tests/source/struct_lits_visual_multiline.rs | 1 + tests/source/structs.rs | 1 + tests/target/attrib.rs | 1 + tests/target/comment.rs | 2 ++ tests/target/comment2.rs | 2 ++ tests/target/comment3.rs | 2 ++ tests/target/enum.rs | 1 + tests/target/expr.rs | 1 + tests/target/hard-tabs.rs | 1 + tests/target/multiple.rs | 1 + tests/target/struct_lits.rs | 1 + tests/target/struct_lits_multiline.rs | 1 + tests/target/struct_lits_visual.rs | 1 + tests/target/struct_lits_visual_multiline.rs | 1 + tests/target/structs.rs | 1 + 28 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 091b4293ad3..eb6c5fc75ec 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -81,7 +81,7 @@ pub fn rewrite_comment(orig: &str, result.push_str(line_start); } - if line.len() > max_chars { + if config.wrap_comments && line.len() > max_chars { let rewrite = try_opt!(rewrite_string(line, &fmt)); result.push_str(&rewrite); } else { @@ -439,7 +439,8 @@ mod test { #[test] #[cfg_attr(rustfmt, rustfmt_skip)] fn format_comments() { - let config = Default::default(); + let mut config: ::config::Config = Default::default(); + config.wrap_comments = true; assert_eq!("/* test */", rewrite_comment(" //test", true, 100, Indent::new(0, 100), &config).unwrap()); assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10, diff --git a/src/config.rs b/src/config.rs index 068ba136bb5..9f260f93ab8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -294,11 +294,11 @@ create_config! { report_fixme: ReportTactic, ReportTactic::Never, "Report all, none or unnumbered occurrences of FIXME in source file comments"; chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base"; - // Alphabetically, case sensitive. reorder_imports: bool, false, "Reorder import statements alphabetically"; single_line_if_else: bool, false, "Put else on same line as closing brace for if statements"; format_strings: bool, true, "Format string literals, or leave as is"; chains_overflow_last: bool, true, "Allow last call in method chain to break the line"; take_source_hints: bool, true, "Retain some formatting characteristics from the source code"; hard_tabs: bool, false, "Use tab characters for indentation, spaces for alignment"; + wrap_comments: bool, false, "Break comments to fit on the line"; } diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index ac44a6504fd..a47c2507156 100644 --- a/tests/source/attrib.rs +++ b/tests/source/attrib.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test attributes and doc comments are preserved. /// Blah blah blah. diff --git a/tests/source/comment.rs b/tests/source/comment.rs index 34b5de79b75..8de3c2ed1cd 100644 --- a/tests/source/comment.rs +++ b/tests/source/comment.rs @@ -1,3 +1,5 @@ +// rustfmt-wrap_comments: true + //! Doc comment fn test() { // comment diff --git a/tests/source/comment2.rs b/tests/source/comment2.rs index 81478621bd9..d68bb5483dc 100644 --- a/tests/source/comment2.rs +++ b/tests/source/comment2.rs @@ -1,2 +1,4 @@ +// rustfmt-wrap_comments: true + /// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly and justly. pub mod foo {} diff --git a/tests/source/comment3.rs b/tests/source/comment3.rs index ed54605f727..f19a8586334 100644 --- a/tests/source/comment3.rs +++ b/tests/source/comment3.rs @@ -1,3 +1,5 @@ +// rustfmt-wrap_comments: true + //! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly and justly. pub mod foo {} diff --git a/tests/source/enum.rs b/tests/source/enum.rs index eba75877277..e55da640d98 100644 --- a/tests/source/enum.rs +++ b/tests/source/enum.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Enums test #[atrr] diff --git a/tests/source/expr.rs b/tests/source/expr.rs index b5a22479058..26b22ed29be 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test expressions fn foo() -> bool { diff --git a/tests/source/hard-tabs.rs b/tests/source/hard-tabs.rs index d9a46800246..290dbfc616d 100644 --- a/tests/source/hard-tabs.rs +++ b/tests/source/hard-tabs.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-hard_tabs: true fn main() { diff --git a/tests/source/multiple.rs b/tests/source/multiple.rs index 4f47aff0544..38d7d8ca941 100644 --- a/tests/source/multiple.rs +++ b/tests/source/multiple.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test of lots of random stuff. // FIXME split this into multiple, self-contained tests. diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs index aecbc285fc6..216ce08099d 100644 --- a/tests/source/struct_lits.rs +++ b/tests/source/struct_lits.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Struct literal expressions. fn main() { diff --git a/tests/source/struct_lits_multiline.rs b/tests/source/struct_lits_multiline.rs index d0cf7d4069f..b6395884713 100644 --- a/tests/source/struct_lits_multiline.rs +++ b/tests/source/struct_lits_multiline.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_multiline_style: ForceMulti // Struct literal expressions. diff --git a/tests/source/struct_lits_visual.rs b/tests/source/struct_lits_visual.rs index 6b78df7e0f3..f483b08b625 100644 --- a/tests/source/struct_lits_visual.rs +++ b/tests/source/struct_lits_visual.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // Struct literal expressions. diff --git a/tests/source/struct_lits_visual_multiline.rs b/tests/source/struct_lits_visual_multiline.rs index 192d88a3903..58be4da68ad 100644 --- a/tests/source/struct_lits_visual_multiline.rs +++ b/tests/source/struct_lits_visual_multiline.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // rustfmt-struct_lit_multiline_style: ForceMulti diff --git a/tests/source/structs.rs b/tests/source/structs.rs index 2bdfe7325bc..94c58b2996c 100644 --- a/tests/source/structs.rs +++ b/tests/source/structs.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true /// A Doc comment #[AnAttribute] diff --git a/tests/target/attrib.rs b/tests/target/attrib.rs index 62657ad3b5d..0789efc2b63 100644 --- a/tests/target/attrib.rs +++ b/tests/target/attrib.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test attributes and doc comments are preserved. /// Blah blah blah. diff --git a/tests/target/comment.rs b/tests/target/comment.rs index 575631cd3be..c3191381653 100644 --- a/tests/target/comment.rs +++ b/tests/target/comment.rs @@ -1,3 +1,5 @@ +// rustfmt-wrap_comments: true + //! Doc comment fn test() { // comment diff --git a/tests/target/comment2.rs b/tests/target/comment2.rs index 885964afee2..cecb7b0d95f 100644 --- a/tests/target/comment2.rs +++ b/tests/target/comment2.rs @@ -1,3 +1,5 @@ +// rustfmt-wrap_comments: true + /// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly /// and justly. pub mod foo { diff --git a/tests/target/comment3.rs b/tests/target/comment3.rs index c9123d4e076..24598931ed1 100644 --- a/tests/target/comment3.rs +++ b/tests/target/comment3.rs @@ -1,3 +1,5 @@ +// rustfmt-wrap_comments: true + //! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly //! and justly. diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 04391d8f30c..9278488fecf 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Enums test #[atrr] diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 4b4afaa99e5..bfd6161e4d8 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test expressions fn foo() -> bool { diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index 21155218111..19a0182fdaa 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-hard_tabs: true fn main() { diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 7d6513f70b7..a806f62705e 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Test of lots of random stuff. // FIXME split this into multiple, self-contained tests. diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index 66fb4925042..e0b29184162 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // Struct literal expressions. fn main() { diff --git a/tests/target/struct_lits_multiline.rs b/tests/target/struct_lits_multiline.rs index 2670ef6de1d..893c9dba888 100644 --- a/tests/target/struct_lits_multiline.rs +++ b/tests/target/struct_lits_multiline.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_multiline_style: ForceMulti // Struct literal expressions. diff --git a/tests/target/struct_lits_visual.rs b/tests/target/struct_lits_visual.rs index 86812c147a1..5ebc3a8684f 100644 --- a/tests/target/struct_lits_visual.rs +++ b/tests/target/struct_lits_visual.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // Struct literal expressions. diff --git a/tests/target/struct_lits_visual_multiline.rs b/tests/target/struct_lits_visual_multiline.rs index 94aa121b7a4..3433b01ff50 100644 --- a/tests/target/struct_lits_visual_multiline.rs +++ b/tests/target/struct_lits_visual_multiline.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // rustfmt-struct_lit_multiline_style: ForceMulti diff --git a/tests/target/structs.rs b/tests/target/structs.rs index 4bc8c6bbe44..bb7cc9d5b7d 100644 --- a/tests/target/structs.rs +++ b/tests/target/structs.rs @@ -1,3 +1,4 @@ +// rustfmt-wrap_comments: true /// A Doc comment #[AnAttribute]