Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
don't force double quoted for strings with newline
Browse files Browse the repository at this point in the history
Signed-off-by: bryanl <bryanliles@gmail.com>
  • Loading branch information
bryanl committed Jul 2, 2018
1 parent c017b64 commit 83f20ee
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
8 changes: 0 additions & 8 deletions ksonnet-gen/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,13 @@ func detectQuoteMode(s string, kind ast.LiteralStringKind) quoteMode {
default:
return quoteModeNone
case ast.StringSingle:
if strings.ContainsAny(s, "\n") {
return quoteModeDouble
}

// Go with single unless there's only single quotes already.
useSingle := !(hasSingle && !hasDouble)
if useSingle {
return quoteModeSingle
}

case ast.StringDouble:
if strings.ContainsAny(s, "\n") {
return quoteModeDouble
}

// Cases:
// 1. [" 'abc' "] -> [" 'abc' "]
// 2. [" \"abc\" "] -> [' "abc" ']
Expand Down
2 changes: 1 addition & 1 deletion ksonnet-gen/printer/testdata/literal_with_newline
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
foo: "value1\nvalue2",
foo: 'value1\nvalue2',
}

0 comments on commit 83f20ee

Please sign in to comment.