Skip to content

Commit

Permalink
Fix interpolation helper for Elixir 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Apr 5, 2021
1 parent bd56b12 commit be5c628
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/credo/code/interpolation_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ defmodule Credo.Code.InterpolationHelper do

# TODO: this seems to be wrong. the closing """ determines the
# indentation, not the first line of the heredoc.
padding_in_first_line = determine_padding_at_start_of_line(first_line_in_heredoc)
padding_in_first_line = determine_heredoc_padding_at_start_of_line(first_line_in_heredoc)

list
|> find_interpolations(source)
Expand Down Expand Up @@ -215,7 +215,18 @@ defmodule Credo.Code.InterpolationHelper do
nil
end

defp determine_padding_at_start_of_line(line, regex \\ ~r/^\s+/) do
if Version.match?(System.version(), ">= 1.12.0-rc") do
# Elixir >= 1.12.0
#
defp determine_heredoc_padding_at_start_of_line(_line), do: 0
else
# Elixir < 1.12.0
#
defp determine_heredoc_padding_at_start_of_line(line),
do: determine_padding_at_start_of_line(line, ~r/^\s+/)
end

defp determine_padding_at_start_of_line(line, regex) do
regex
|> Regex.run(line)
|> List.wrap()
Expand Down

0 comments on commit be5c628

Please sign in to comment.