exercism / exercism/elixir-representer

Normalization of aliases and imports

Đang mở
#40 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
x:action/improve x:knowledge/elementary x:module/representer x:size/large x:type/coding
Ngôn ngữ chính
Elixir
Star
11
Fork
8
Merge trung bình
11 ngày 3 giờ
Pull request đã merge (30 ngày)
1

Mô tả

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

## Example input

```elixir
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

```elixir
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

```elixir
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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.