Skip to content

Commit cdc6209

Browse files
committed
Fix formatting for CHAR node when single_quotes plugin is enabled
1 parent 909b45a commit cdc6209

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: lib/syntax_tree/node.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def format(q)
288288
q.text(value)
289289
else
290290
q.text(q.quote)
291-
q.text(value[1] == "\"" ? "\\\"" : value[1])
291+
double_quotation = q.quote == "'" ? "\"" : "\\\""
292+
q.text(value[1] == "\"" ? double_quotation : value[1])
292293
q.text(q.quote)
293294
end
294295
end

Diff for: test/plugin/single_quotes_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def test_empty_string_literal
88
assert_format("''\n", "\"\"")
99
end
1010

11+
def test_character_literal
12+
assert_format("'\"'\n", "?\"")
13+
end
14+
1115
def test_string_literal
1216
assert_format("'string'\n", "\"string\"")
1317
end

0 commit comments

Comments
 (0)