Merge pull request #1724 from topecongiro/multiline-string-lit

Align multiline string literal
This commit is contained in:
Nick Cameron
2017-06-19 13:02:21 +12:00
committed by GitHub
5 changed files with 24 additions and 5 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ fn print_usage(opts: &Options, reason: &str) {
let msg = format!("{}\nusage: cargo fmt [options]", reason);
println!(
"{}\nThis utility formats all bin and lib files of the current crate using rustfmt. \
Arguments after `--` are passed to rustfmt.",
Arguments after `--` are passed to rustfmt.",
opts.usage(&msg)
);
}
+1 -1
View File
@@ -144,7 +144,7 @@ fn make_opts() -> Options {
"",
"config-path",
"Recursively searches the given path for the rustfmt.toml config file. If not \
found reverts to the input file path",
found reverts to the input file path",
"[Path for the configuration file]",
);
opts.optopt(
+1 -1
View File
@@ -55,7 +55,7 @@ pub fn output_checkstyle_file<T>(
write!(
writer,
"<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
/>",
/>",
mismatch.line_number,
message
)?;
+20 -1
View File
@@ -1857,7 +1857,26 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
let string_lit = context.snippet(span);
if !context.config.format_strings() && !context.config.force_format_strings() {
return Some(string_lit);
if string_lit
.lines()
.rev()
.skip(1)
.all(|line| line.ends_with('\\'))
{
let new_indent = shape.visual_indent(1).indent;
return Some(String::from(
string_lit
.lines()
.map(|line| {
new_indent.to_string(context.config) + line.trim_left()
})
.collect::<Vec<_>>()
.join("\n")
.trim_left(),
));
} else {
return Some(string_lit);
}
}
if !context.config.force_format_strings() &&
+1 -1
View File
@@ -228,7 +228,7 @@ fn deserialize<D>(_: D) -> Result<Self, D::Error>
{
panic!(
"FileLines cannot be deserialized from a project rustfmt.toml file: please \
specify it via the `--file-lines` option instead"
specify it via the `--file-lines` option instead"
);
}
}