Skip to content

Commit 1968bf1

Browse files
committed
dont run charlist transforms on higher versions
1 parent bf47ef9 commit 1968bf1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/style/single_node.ex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ defmodule Styler.Style.SingleNode do
3232

3333
def run({node, meta}, ctx), do: {:cont, {style(node), meta}, ctx}
3434

35-
# Our use of the `literal_encoder` option of `Code.string_to_quoted_with_comments!/2` creates
36-
# invalid charlists literal AST nodes from `'foo'`. this rewrites them to use the `~c` sigil
37-
# 'foo' => ~c"foo".
38-
defp style({:__block__, meta, [chars]} = node) when is_list(chars) do
39-
if meta[:delimiter] == "'" do
40-
{:sigil_c, Keyword.put(meta, :delimiter, "\""), [{:<<>>, [line: meta[:line]], [List.to_string(chars)]}, []]}
41-
else
42-
node
35+
if Version.match?(System.version(), "< 1.15.0-dev") do
36+
# Our use of the `literal_encoder` option of `Code.string_to_quoted_with_comments!/2` creates
37+
# invalid charlists literal AST nodes from `'foo'`. this rewrites them to use the `~c` sigil
38+
# 'foo' => ~c"foo".
39+
defp style({:__block__, meta, [chars]} = node) when is_list(chars) do
40+
if meta[:delimiter] == "'" do
41+
{:sigil_c, Keyword.put(meta, :delimiter, "\""), [{:<<>>, [line: meta[:line]], [List.to_string(chars)]}, []]}
42+
else
43+
node
44+
end
4345
end
4446
end
4547

test/style/single_node_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
defmodule Styler.Style.SingleNodeTest do
1212
use Styler.StyleCase, async: true
1313

14+
# elixir's formatter >= 1.15 does this for us.
1415
test "charlist literals: rewrites single quote charlists to ~c" do
1516
assert_style("'foo'", ~s|~c"foo"|)
1617
assert_style(~s|'"'|, ~s|~c"\\""|)
17-
# elixir's formatter >= 1.15 does this for us.
1818
assert_style("''", ~s|~c""|)
1919
end
2020

0 commit comments

Comments
 (0)