Merge pull request #1551 from topecongiro/else-if-early-line-break

Forbid early line breaks inside else if
This commit is contained in:
Nick Cameron 2017-05-15 08:59:03 +12:00 committed by GitHub
commit ebb26db68b
2 changed files with 25 additions and 32 deletions

View File

@ -52,37 +52,35 @@ pub fn rewrite_comment(orig: &str,
return light_rewrite_comment(orig, shape.indent, config);
}
let (opener, closer, line_start) =
if block_style {
let (opener, closer, line_start) = if block_style {
("/* ", " */", " * ")
} else if !config.normalize_comments {
if orig.starts_with("/**") && !orig.starts_with("/**/") {
("/** ", " **/", " ** ")
} else if orig.starts_with("/*!") {
("/*! ", " */", " * ")
} else if orig.starts_with("/*") {
("/* ", " */", " * ")
} else if !config.normalize_comments {
if orig.starts_with("/**") && !orig.starts_with("/**/") {
("/** ", " **/", " ** ")
} else if orig.starts_with("/*!") {
("/*! ", " */", " * ")
} else if orig.starts_with("/*") {
("/* ", " */", " * ")
} else if orig.starts_with("///") {
("/// ", "", "/// ")
} else if orig.starts_with("//!") {
("//! ", "", "//! ")
} else {
("// ", "", "// ")
}
} else if orig.starts_with("///") ||
(orig.starts_with("/**") && !orig.starts_with("/**/")) {
} else if orig.starts_with("///") {
("/// ", "", "/// ")
} else if orig.starts_with("//!") || orig.starts_with("/*!") {
} else if orig.starts_with("//!") {
("//! ", "", "//! ")
} else if is_custom_comment(orig) {
if orig.chars().nth(3) == Some(' ') {
(&orig[0..4], "", &orig[0..4])
} else {
(&orig[0..3], "", &orig[0..3])
}
} else {
("// ", "", "// ")
};
}
} else if orig.starts_with("///") || (orig.starts_with("/**") && !orig.starts_with("/**/")) {
("/// ", "", "/// ")
} else if orig.starts_with("//!") || orig.starts_with("/*!") {
("//! ", "", "//! ")
} else if is_custom_comment(orig) {
if orig.chars().nth(3) == Some(' ') {
(&orig[0..4], "", &orig[0..4])
} else {
(&orig[0..3], "", &orig[0..3])
}
} else {
("// ", "", "// ")
};
let max_chars = shape
.width

View File

@ -987,12 +987,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
block_str);
if let Some(else_block) = self.else_block {
// Since this is an else block, we should not indent for the assignment preceding
// the original if, so set shape.offset to shape.indent.alignment.
let shape = Shape {
offset: shape.indent.alignment,
..shape
};
let shape = Shape::indented(shape.indent, context.config);
let mut last_in_chain = false;
let rewrite = match else_block.node {
// If the else expression is another if-else expression, prevent it