Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalization of aliases and imports #40

Open
jiegillet opened this issue Oct 31, 2021 · 2 comments
Open

Normalization of aliases and imports #40

jiegillet opened this issue Oct 31, 2021 · 2 comments
Labels
x:action/improve Improve existing functionality/content x:knowledge/elementary Little Exercism knowledge required x:module/representer Work on Representers x:size/large Large amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)

Comments

@jiegillet
Copy link
Contributor

Aliases and imports usually refer to external functions so names should be handled accordingly

Example input

defmodule A do
  import B, only: [b_function: 1]
  import C, except: [c_function: 1]
  alias D, as: Dog
  def use_b(x), do: x |> b_function
  def use_c(c_function), do: c_function(0)
  def use_d(y), do: Dog.sniff(y)
end

Desired output

defmodule(PLACEHOLDER_1) do
  import(B, only: [b_function: 1])
  import(C, except: [c_function: 1])
  alias(D, as: PLACEHOLDER_2)
  def(PLACEHOLDER_3(PLACEHOLDER_4)) do
    PLACEHOLDER_4 |> b_function
  end
  def(PLACEHOLDER_5(PLACEHOLDER_6)) do
    PLACEHOLDER_6(0)
  end
  def(PLACEHOLDER_7(PLACEHOLDER_8)) do
    PLACEHOLDER_2.sniff(PLACEHOLDER_8)
  end
end

b_function is imported so should appear as it is. c_function is excluded, so any mention of it is a local variable and should have a placeholder (current behavior already). Dog is an alias so should be replaced by a placeholder (possible overlap with #33).

Current output

defmodule(PLACEHOLDER_1) do
  import(B, only: [b_function: 1])
  import(C, except: [c_function: 1])
  alias(D, as: Dog)
  def(PLACEHOLDER_2(PLACEHOLDER_3)) do
    PLACEHOLDER_3 |> PLACEHOLDER_4
  end
  def(PLACEHOLDER_5(PLACEHOLDER_6)) do
    PLACEHOLDER_6(0)
  end
  def(PLACEHOLDER_7(PLACEHOLDER_8)) do
    Dog.sniff(PLACEHOLDER_8)
  end
end

In the case of import X where X is a standard library, it is possible to lookup all functions, so these should not de replaced either.

@jiegillet jiegillet changed the title Normalization of aliases Normalization of aliases and imports Oct 31, 2021
@angelikatyborska angelikatyborska added x:action/improve Improve existing functionality/content x:knowledge/elementary Little Exercism knowledge required x:module/representer Work on Representers x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises) x:size/large Large amount of work labels Oct 31, 2021
@safwansamsudeen
Copy link

Should this issue be closed?

@angelikatyborska
Copy link
Contributor

This issue has been addresses only partially in #44

There is the remaining part about imports and :only/:except, but a lot has changed since this issue was opened. Current behavior is that any module or function that is not defined locally, doesn't get a placeholder. For example:

Input

defmodule A do
  import B, only: [b_function: 1]
  import C, except: [c_function: 1]
  alias D, as: Dog

  def use_b(x) do
    x |> b_function()
  end

  def use_c() do
    c_function(0)
  end

  def use_d(y) do
    Dog.sniff(y)
  end
end

Output

defmodule Placeholder_1 do
  alias D, as: Placeholder_2
  import B, only: [b_function: 1]
  import C, except: [c_function: 1]

  def placeholder_3(placeholder_4) do
    placeholder_4 |> b_function()
  end

  def placeholder_5() do
    c_function(0)
  end

  def placeholder_6(placeholder_7) do
    Placeholder_2.sniff(placeholder_7)
  end
end

That kinda makes sense to me. I'm not sure if I would change anything about this. But it's hard to judge, the representer doesn't really get any use (there are still only 6 comments added to elixir representations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:action/improve Improve existing functionality/content x:knowledge/elementary Little Exercism knowledge required x:module/representer Work on Representers x:size/large Large amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)
Projects
None yet
Development

No branches or pull requests

3 participants