Skip to content

Commit ae9ce7b

Browse files
author
Seiichi Uchida
committed
Align multiline string literal
1 parent be18e7a commit ae9ce7b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/expr.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,26 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
18561856
let string_lit = context.snippet(span);
18571857

18581858
if !context.config.format_strings() && !context.config.force_format_strings() {
1859-
return Some(string_lit);
1859+
if string_lit
1860+
.lines()
1861+
.rev()
1862+
.skip(1)
1863+
.all(|line| line.ends_with('\\'))
1864+
{
1865+
let new_indent = shape.visual_indent(1).indent;
1866+
return Some(String::from(
1867+
string_lit
1868+
.lines()
1869+
.map(|line| {
1870+
new_indent.to_string(context.config) + line.trim_left()
1871+
})
1872+
.collect::<Vec<_>>()
1873+
.join("\n")
1874+
.trim_left(),
1875+
));
1876+
} else {
1877+
return Some(string_lit);
1878+
}
18601879
}
18611880

18621881
if !context.config.force_format_strings() &&

0 commit comments

Comments
 (0)