exercism / elixir-analyzer

GNU Affero General Public License v3.0
30 stars 32 forks source link

Basketball website: `get_in` call when using a pipe is not detected #330

Closed vecerek closed 2 years ago

vecerek commented 2 years ago

I'm receiving the following feedback:

Essential Make sure to only use use get_in/2 in BasketballWebsite.get_in_path/2 and not in BasketballWebsite.extract_from_path/2. The purpose of this exercise is to practice using the Access Behaviour in two different ways, first directly using the data[key] syntax, and then indirectly using the get_in_path/2.

For the following code:

defmodule BasketballWebsite do
  def extract_from_path(data, path), do: do_extract_from_path(data, String.split(path, "."))
  defp do_extract_from_path(nil, _), do: nil
  defp do_extract_from_path(data, []), do: data
  defp do_extract_from_path(data, [head | tail]), do: do_extract_from_path(data[head], tail)

  def get_in_path(data, path), do: data |> get_in(String.split(path, "."))
end

I'm only using get_in inside get_in_path/2.

angelikatyborska commented 2 years ago

Thanks for the report! There is a bug in detecting that you did use get_in in get_in_path. For some reason, this code is correct:

def get_in_path(data, path) do
  get_in(data, String.split(path, "."))
end

But this code makes the analyzer think get_in wasn't used:

def get_in_path(data, path) do
  data |> get_in(String.split(path, "."))
end