Repository: adobe/elixir-styler (elixir)

Issue:
Produces compiler errors for Ecto queries using "in" macro
## Elixir / OTP Version
```
❯ cat .tool-versions 
elixir 1.14.1-otp-25
erlang 25.1.1
```

## Current Behaviour

For several of my work projects, we do `require Ecto.Query` (instead of `import Ecto.Query, only: ...`) and then call `Ecto.Query.from(...)`. Inside of [the `from` macro](https://github.com/elixir-ecto/ecto/blob/v3.10.1/lib/ecto/query.ex#L939), an unqualified `in` is valid. However, `elixir-styler` makes the following change:

<img width="1137" alt="Screenshot 2023-05-04 at 8 22 32 AM" src="https://user-images.githubusercontent.com/3588798/236254197-8f819b66-b088-44fb-a180-d8ed3b636e2b.png">

<img width="1165" alt="Screenshot 2023-05-04 at 8 10 36 AM" src="https://user-images.githubusercontent.com/3588798/236251322-8bae6844-4450-4e90-959d-d63b304d2bda.png">

Which causes a compilation error:
```
syntax error before: in. "in" is a reserved word in Elixir and therefore its usage is limited. For instance, it can't be used as a variable or be defined nor invoked as a regular function
```

A fix in this case is to change `in` to `Ecto.Query.in`.

## Expected Behaviour

I'm not sure how to avoid this, unless `elixir-styler` is able to detect which functions are macros and skip them or automatically fully qualify them?

Pull request description:
Bug: include Ecto.Query.from as a valid pipe start
Closes #24

This error makes me think that it's likely that other macro DSLs will work poorly with the pipes op, but we'll see what crops up

Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index 6b582d2..52d3765 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -179,6 +179,8 @@ defmodule Styler.Style.Pipes do
   defp valid_pipe_start?({:unquote, _, _}), do: true
   # ecto
   defp valid_pipe_start?({:from, _, _}), do: true
+  defp valid_pipe_start?({{:., _, [{_, _, [:Query]}, :from]}, _, _}), do: true
+  defp valid_pipe_start?({{:., _, [{_, _, [:Ecto, :Query]}, :from]}, _, _}), do: true
   # most of these values were lifted directly from credo's pipe_chain_start.ex
   @value_constructors ~w(% %{} .. <<>> @ {} & fn)a
   @simple_operators ~w(++ -- && ||)a


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index c0bb6e6..c669942 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -473,11 +473,13 @@ defmodule Styler.Style.PipesTest do
     end
 
     test "allows ecto's from" do
-      assert_style("""
-      from(foo in Bar, where: foo.bool)
-      |> some_query_helper()
-      |> Repo.all()
-      """)
+      for from <- ~w(from Query.from Ecto.Query.from) do
+        assert_style("""
+        #{from}(foo in Bar, where: foo.bool)
+        |> some_query_helper()
+        |> Repo.all()
+        """)
+      end
     end
 
     test "extracts >0 arity functions" do