Skip to content

Format strings option https://github.com/nrc/rustfmt/issues/202 #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ create_config! {
expr_indent_style: BlockIndentStyle,
closure_indent_style: BlockIndentStyle,
single_line_if_else: bool,
format_strings: bool,
}

impl Default for Config {
Expand All @@ -104,6 +105,7 @@ impl Default for Config {
expr_indent_style: BlockIndentStyle::Tabbed,
closure_indent_style: BlockIndentStyle::Visual,
single_line_if_else: false,
format_strings: true,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ fn rewrite_string_lit(context: &RewriteContext,
width: usize,
offset: usize)
-> Option<String> {
if context.config.format_strings == false {
return Some(context.snippet(span));
}
// Check if there is anything to fix: we always try to fixup multi-line
// strings, or if the string is too long for the line.
let l_loc = context.codemap.lookup_char_pos(span.lo);
Expand Down
1 change: 1 addition & 0 deletions tests/config/small_tabs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ reorder_imports = false
expr_indent_style = "Tabbed"
closure_indent_style = "Visual"
single_line_if_else = false
format_strings = true
22 changes: 22 additions & 0 deletions tests/target/string-lit-custom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// rustfmt-format_strings: false

fn main() {
let expected = "; ModuleID = \'foo\'

; Function Attrs: nounwind
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0

declare i32 @write(i32, i8*, i32)

declare i32 @putchar(i32)

declare i32 @getchar()

define i32 @main() {
entry:
ret i32 0
}

attributes #0 = { nounwind }
";
}