Skip to content

Commit

Permalink
Allow Kernel unary ! and not as valid pipe starts. Closes #183
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Jul 15, 2024
1 parent 388f2d8 commit aee6e71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ they can and will change without that change being reflected in Styler's semanti
### Fixes

* fix `with` arrow replacement + redundant body removal creating invalid statements (#184, h/t @JesseHerrick)
* allow Kernel unary `!` and `not` as valid pipe starts (#183, h/t @nherzing)

## 1.0.0-rc.2

Expand Down
2 changes: 1 addition & 1 deletion lib/style/pipes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Styler.Style.Pipes do
# most of these values were lifted directly from credo's pipe_chain_start.ex
@literal ~w(__block__ __aliases__ unquote)a
@value_constructors ~w(% %{} .. ..// <<>> @ {} ^ & fn from)a
@kernel_ops ~w(++ -- && || in - * + / > < <= >= == and or != !== === <>)a
@kernel_ops ~w(++ -- && || in - * + / > < <= >= == and or != !== === <> ! not)a
@special_ops ~w(||| &&& <<< >>> <<~ ~>> <~ ~> <~>)a
@special_ops @literal ++ @value_constructors ++ @kernel_ops ++ @special_ops

Expand Down
7 changes: 7 additions & 0 deletions test/style/pipes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ defmodule Styler.Style.PipesTest do
end

describe "valid pipe starts & unpiping" do
test "kernel unary starts" do
assert_style("!b |> c() |> d()", "!b |> c() |> d()")
assert_style("!x(b) |> c() |> d()")
assert_style("not(b) |> c() |> d()", "not b |> c() |> d()")
assert_style("not x(b) |> c() |> d()")
end

test "writes brackets for unpiped kwl" do
assert_style("foo(kwl: :arg) |> bar()", "[kwl: :arg] |> foo() |> bar()")
assert_style("%{a: foo(a: :b, c: :d) |> bar()}", "%{a: [a: :b, c: :d] |> foo() |> bar()}")
Expand Down

0 comments on commit aee6e71

Please sign in to comment.