Skip to content

Commit 81c8c02

Browse files
committed
Merge pull request #239 from sinhpham/format_strings_option
Format strings option https://github.com/nrc/rustfmt/issues/202
2 parents 1d7bb8f + 55fe34a commit 81c8c02

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ create_config! {
8080
expr_indent_style: BlockIndentStyle,
8181
closure_indent_style: BlockIndentStyle,
8282
single_line_if_else: bool,
83+
format_strings: bool,
8384
}
8485

8586
impl Default for Config {
@@ -104,6 +105,7 @@ impl Default for Config {
104105
expr_indent_style: BlockIndentStyle::Tabbed,
105106
closure_indent_style: BlockIndentStyle::Visual,
106107
single_line_if_else: false,
108+
format_strings: true,
107109
}
108110
}
109111

src/expr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,9 @@ fn rewrite_string_lit(context: &RewriteContext,
828828
width: usize,
829829
offset: usize)
830830
-> Option<String> {
831+
if context.config.format_strings == false {
832+
return Some(context.snippet(span));
833+
}
831834
// Check if there is anything to fix: we always try to fixup multi-line
832835
// strings, or if the string is too long for the line.
833836
let l_loc = context.codemap.lookup_char_pos(span.lo);

tests/config/small_tabs.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ reorder_imports = false
1616
expr_indent_style = "Tabbed"
1717
closure_indent_style = "Visual"
1818
single_line_if_else = false
19+
format_strings = true

tests/target/string-lit-custom.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// rustfmt-format_strings: false
2+
3+
fn main() {
4+
let expected = "; ModuleID = \'foo\'
5+
6+
; Function Attrs: nounwind
7+
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0
8+
9+
declare i32 @write(i32, i8*, i32)
10+
11+
declare i32 @putchar(i32)
12+
13+
declare i32 @getchar()
14+
15+
define i32 @main() {
16+
entry:
17+
ret i32 0
18+
}
19+
20+
attributes #0 = { nounwind }
21+
";
22+
}

0 commit comments

Comments
 (0)