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.
This commit is contained in:
Nick Cameron 2015-11-10 08:03:01 +13:00
parent 1c0934772c
commit b7d61254a7
28 changed files with 36 additions and 3 deletions

View File

@ -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,

View File

@ -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";
}

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test attributes and doc comments are preserved.
/// Blah blah blah.

View File

@ -1,3 +1,5 @@
// rustfmt-wrap_comments: true
//! Doc comment
fn test() {
// comment

View File

@ -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 {}

View File

@ -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 {}

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Enums test
#[atrr]

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test expressions
fn foo() -> bool {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-hard_tabs: true
fn main() {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test of lots of random stuff.
// FIXME split this into multiple, self-contained tests.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Struct literal expressions.
fn main() {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_multiline_style: ForceMulti
// Struct literal expressions.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_style: Visual
// Struct literal expressions.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_style: Visual
// rustfmt-struct_lit_multiline_style: ForceMulti

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
/// A Doc comment
#[AnAttribute]

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test attributes and doc comments are preserved.
/// Blah blah blah.

View File

@ -1,3 +1,5 @@
// rustfmt-wrap_comments: true
//! Doc comment
fn test() {
// comment

View File

@ -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 {

View File

@ -1,3 +1,5 @@
// rustfmt-wrap_comments: true
//! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
//! and justly.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Enums test
#[atrr]

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test expressions
fn foo() -> bool {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-hard_tabs: true
fn main() {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Test of lots of random stuff.
// FIXME split this into multiple, self-contained tests.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// Struct literal expressions.
fn main() {

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_multiline_style: ForceMulti
// Struct literal expressions.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_style: Visual
// Struct literal expressions.

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-struct_lit_style: Visual
// rustfmt-struct_lit_multiline_style: ForceMulti

View File

@ -1,3 +1,4 @@
// rustfmt-wrap_comments: true
/// A Doc comment
#[AnAttribute]