Skip to content

Commit e61a96e

Browse files
authored
Use explicit steps to remove 1.16 deprecation warning (#322)
1 parent 55686be commit e61a96e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/excoveralls/cobertura.ex

+9-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ defmodule ExCoveralls.Cobertura do
173173
c_paths
174174
|> Enum.find_value(package_name, fn c_path ->
175175
if String.starts_with?(package_name, c_path) do
176-
String.slice(package_name, (String.length(c_path) + 1)..-1)
176+
String.slice(package_name, get_slice_range_for_package_name(c_path))
177177
else
178178
false
179179
end
@@ -183,6 +183,14 @@ defmodule ExCoveralls.Cobertura do
183183
|> to_charlist()
184184
end
185185

186+
# TODO: Remove when we require Elixir 1.12 as minimum and inline it with range syntax
187+
if Version.match?(System.version(), ">= 1.12.0") do
188+
# We use Range.new/3 because using x..y//step would give a syntax error on Elixir < 1.12
189+
defp get_slice_range_for_package_name(c_path), do: Range.new(String.length(c_path) + 1, -1, 1)
190+
else
191+
defp get_slice_range_for_package_name(c_path), do: (String.length(c_path) + 1)..-1
192+
end
193+
186194
defp rate(valid_lines) when length(valid_lines) == 0, do: 0.0
187195

188196
defp rate(valid_lines) do

0 commit comments

Comments
 (0)