From be5c628c5ebaa5e9b09c896cbcb1400fd0e53089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Mon, 5 Apr 2021 17:08:27 +0200 Subject: [PATCH] Fix interpolation helper for Elixir 1.12 --- lib/credo/code/interpolation_helper.ex | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/credo/code/interpolation_helper.ex b/lib/credo/code/interpolation_helper.ex index 4b0df8a28..0751f3575 100644 --- a/lib/credo/code/interpolation_helper.ex +++ b/lib/credo/code/interpolation_helper.ex @@ -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) @@ -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()