diff --git a/lib/credo/backports.ex b/lib/credo/backports.ex deleted file mode 100644 index cabb63bf4..000000000 --- a/lib/credo/backports.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Credo.Backports do - defmodule Enum do - if Version.match?(System.version(), ">= 1.12.0-rc") do - def slice(a, x..y) do - Elixir.Enum.slice(a, x..y//1) - end - end - - def slice(a, b) do - Elixir.Enum.slice(a, b) - end - end - - defmodule String do - if Version.match?(System.version(), ">= 1.12.0-rc") do - def slice(a, x..y) do - Elixir.String.slice(a, x..y//1) - end - end - - def slice(a, b) do - Elixir.String.slice(a, b) - end - end -end diff --git a/lib/credo/check/config_comment.ex b/lib/credo/check/config_comment.ex index def6d1943..71ff518aa 100644 --- a/lib/credo/check/config_comment.ex +++ b/lib/credo/check/config_comment.ex @@ -135,7 +135,7 @@ defmodule Credo.Check.ConfigComment do defp value_for(param_string) do if regex_value?(param_string) do param_string - |> Credo.Backports.String.slice(1..-2//-1) + |> String.slice(1..-2//1) |> Regex.compile!("i") else String.to_atom("Elixir.#{param_string}") diff --git a/lib/credo/check/consistency/multi_alias_import_require_use/collector.ex b/lib/credo/check/consistency/multi_alias_import_require_use/collector.ex index 748338526..0ba238089 100644 --- a/lib/credo/check/consistency/multi_alias_import_require_use/collector.ex +++ b/lib/credo/check/consistency/multi_alias_import_require_use/collector.ex @@ -42,7 +42,7 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUse.Collector do aliases = case arguments do [{:__aliases__, _, nested_modules}] when length(nested_modules) > 1 -> - base_name = Credo.Backports.Enum.slice(nested_modules, 0..-2//-1) + base_name = Enum.slice(nested_modules, 0..-2//1) {:single, base_name} [{{:., _, [{:__aliases__, _, _namespaces}, :{}]}, _, _nested_aliases}] -> diff --git a/lib/credo/check/consistency/space_around_operators.ex b/lib/credo/check/consistency/space_around_operators.ex index 66ec78d18..f529f57de 100644 --- a/lib/credo/check/consistency/space_around_operators.ex +++ b/lib/credo/check/consistency/space_around_operators.ex @@ -139,7 +139,7 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators do defp number_in_range?(line, column) do line - |> Credo.Backports.String.slice(column..-1) + |> String.slice(column..-1//1) |> String.match?(~r/^\d+\.\./) end @@ -166,13 +166,13 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators do # -1 because we need to subtract the operator binary_pattern_end_after? = line - |> Credo.Backports.String.slice(column..-1) + |> String.slice(column..-1//1) |> String.match?(~r/\>\>/) # -1 because we need to subtract the operator typed_after? = line - |> Credo.Backports.String.slice(column..-1) + |> String.slice(column..-1//1) |> String.match?(~r/^\s*(integer|native|signed|unsigned|binary|size|little|float)/) # -2 because we need to subtract the operator diff --git a/lib/credo/check/readability/large_numbers.ex b/lib/credo/check/readability/large_numbers.ex index 6023ba815..783042182 100644 --- a/lib/credo/check/readability/large_numbers.ex +++ b/lib/credo/check/readability/large_numbers.ex @@ -181,12 +181,12 @@ defmodule Credo.Check.Readability.LargeNumbers do Enum.map(allowed_trailing_digits, fn trailing_digits -> if String.length(string) > trailing_digits do base = - Credo.Backports.String.slice(string, 0..(-1 * trailing_digits - 1)) + String.slice(string, 0..(-1 * trailing_digits - 1)//1) |> String.reverse() |> String.replace(~r/(\d{3})(?=\d)/, "\\1_") |> String.reverse() - trailing = Credo.Backports.String.slice(string, (-1 * trailing_digits)..-1) + trailing = String.slice(string, (-1 * trailing_digits)..-1//1) "#{base}_#{trailing}" end @@ -236,7 +236,7 @@ defmodule Credo.Check.Readability.LargeNumbers do ending_of_number = ~r/^([0-9_\.]+)/ - |> Regex.run(Credo.Backports.String.slice(line, (column1 + 1)..-1)) + |> Regex.run(String.slice(line, (column1 + 1)..-1//1)) |> List.wrap() |> List.last() |> to_string() diff --git a/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex b/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex index e70ebf4f0..dc24aedb3 100644 --- a/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex +++ b/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex @@ -89,7 +89,7 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do name_size = text |> to_string |> String.length() skip = (SourceFile.column(source_file, line_no, text) || -1) + name_size - 1 - Credo.Backports.String.slice(line, skip..-1) + String.slice(line, skip..-1//1) end defp issue_for(issue_meta, name, line_no, kind) do diff --git a/lib/credo/check/warning/unused_function_return_helper.ex b/lib/credo/check/warning/unused_function_return_helper.ex index 56d0aba75..fefbd04cf 100644 --- a/lib/credo/check/warning/unused_function_return_helper.ex +++ b/lib/credo/check/warning/unused_function_return_helper.ex @@ -132,7 +132,7 @@ defmodule Credo.Check.Warning.UnusedFunctionReturnHelper do when is_list(arguments) do # IO.inspect(ast, label: "#{unquote(op)} (#{Macro.to_string(candidate)} #{acc})") - head_expression = Credo.Backports.Enum.slice(arguments, 0..-2//-1) + head_expression = Enum.slice(arguments, 0..-2//1) if Credo.Code.contains_child?(head_expression, candidate) do {nil, :VERIFIED} diff --git a/lib/credo/cli/command/diff/task/get_git_diff.ex b/lib/credo/cli/command/diff/task/get_git_diff.ex index 843da8f2a..1a489320f 100644 --- a/lib/credo/cli/command/diff/task/get_git_diff.ex +++ b/lib/credo/cli/command/diff/task/get_git_diff.ex @@ -104,13 +104,13 @@ defmodule Credo.CLI.Command.Diff.Task.GetGitDiff do defp run_credo_on_dir(exec, dirname, previous_git_ref, given_ref) do {previous_argv, _last_arg} = exec.argv - |> Credo.Backports.Enum.slice(1..-1//-1) + |> Enum.slice(1..-1//1) |> Enum.reduce({[], nil}, fn - _, {argv, "--working-dir"} -> {Credo.Backports.Enum.slice(argv, 1..-2//-1), nil} - _, {argv, "--from-git-merge-base"} -> {Credo.Backports.Enum.slice(argv, 1..-2//-1), nil} - _, {argv, "--from-git-ref"} -> {Credo.Backports.Enum.slice(argv, 1..-2//-1), nil} - _, {argv, "--from-dir"} -> {Credo.Backports.Enum.slice(argv, 1..-2//-1), nil} - _, {argv, "--since"} -> {Credo.Backports.Enum.slice(argv, 1..-2//-1), nil} + _, {argv, "--working-dir"} -> {Enum.slice(argv, 1..-2//1), nil} + _, {argv, "--from-git-merge-base"} -> {Enum.slice(argv, 1..-2//1), nil} + _, {argv, "--from-git-ref"} -> {Enum.slice(argv, 1..-2//1), nil} + _, {argv, "--from-dir"} -> {Enum.slice(argv, 1..-2//1), nil} + _, {argv, "--since"} -> {Enum.slice(argv, 1..-2//1), nil} "--show-fixed", {argv, _last_arg} -> {argv, nil} "--show-kept", {argv, _last_arg} -> {argv, nil} ^previous_git_ref, {argv, _last_arg} -> {argv, nil} diff --git a/lib/credo/cli/command/explain/output/default.ex b/lib/credo/cli/command/explain/output/default.ex index e1ea503fe..0492f41f6 100644 --- a/lib/credo/cli/command/explain/output/default.ex +++ b/lib/credo/cli/command/explain/output/default.ex @@ -269,7 +269,7 @@ defmodule Credo.CLI.Command.Explain.Output.Default do |> String.trim() |> String.split("\n") |> Enum.flat_map(&format_explanation(&1, outer_color)) - |> Credo.Backports.Enum.slice(0..-2//-1) + |> Enum.slice(0..-2//1) |> UI.puts() UI.puts_edge([outer_color, :faint]) diff --git a/lib/credo/code/interpolation_helper.ex b/lib/credo/code/interpolation_helper.ex index b64b70e85..deb95034a 100644 --- a/lib/credo/code/interpolation_helper.ex +++ b/lib/credo/code/interpolation_helper.ex @@ -58,7 +58,7 @@ defmodule Credo.Code.InterpolationHelper do line = String.to_charlist(line) part1 = Enum.slice(line, 0, col_start - 1) part2 = String.to_charlist(String.duplicate(char, length)) - part3 = Credo.Backports.Enum.slice(line, (col_end - 1)..-1) + part3 = Enum.slice(line, (col_end - 1)..-1//1) List.to_string(part1 ++ part2 ++ part3) end @@ -271,6 +271,6 @@ defmodule Credo.Code.InterpolationHelper do # col-1 to account for col being 1-based start = max(col_end - 1, 0) - Credo.Backports.String.slice(line, start..-1) + String.slice(line, start..-1) end end