Skip to content

Commit

Permalink
export step macro in locals_without_parens
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ruoss committed Oct 25, 2022
1 parent 48428bf commit 6061fe3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [step: 1, step: 2],
export: [
locals_without_parens: [step: 1, step: 2]
]
]
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- No new entries below this line! -->

## [1.0.1] - 2022-10-25

### Added

- :locals_without_parens export in formatter configuration

## [1.0.0] - 2022-10-12

This is the first release.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ when deriving `Pluggable.Token`

`Pluggable.StepBuilder` works just like `Plug.Builder`. See the
module documentation for instructions.

## Code Formatting

When using the `Pluggable.StepBuilder`, you might want to format the usage
of the `step` macro without parens. To configure the formatter not to add
parens, add this to your `.formatter.exs`:

```elixir
# .formatter.exs
[
import_deps: [:pluggable]
]
```
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Pluggable.MixProject do
use Mix.Project

@source_url "https://github.com/mruoss/pluggable"
@version "1.0.0"
@version "1.0.1"

def project do
[
Expand Down
30 changes: 15 additions & 15 deletions test/pluggable/step_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ defmodule Pluggable.StepBuilderTest do
defmodule Sample do
use Pluggable.StepBuilder, copy_opts_to_assign: :stack

step(:fun, :step1)
step(Module, :step2)
step(Module, :step3)
step :fun, :step1
step Module, :step2
step Module, :step3

def fun(token, opts) do
stack = [{:fun, opts} | token.assigns[:stack]]
Expand All @@ -34,7 +34,7 @@ defmodule Pluggable.StepBuilderTest do
:throw, {:not_found, token} -> assign(token, :not_found, :caught)
end

step(:boom)
step :boom

def boom(token, _opts) do
token = assign(token, :entered_stack, true)
Expand All @@ -45,10 +45,10 @@ defmodule Pluggable.StepBuilderTest do
defmodule Halter do
use Pluggable.StepBuilder

step(:set_step, :first)
step(:set_step, :second)
step(:authorize)
step(:set_step, :end_of_chain_reached)
step :set_step, :first
step :set_step, :second
step :authorize
step :set_step, :end_of_chain_reached

def set_step(token, step), do: assign(token, step, true)

Expand All @@ -68,12 +68,12 @@ defmodule Pluggable.StepBuilderTest do
end

use Pluggable.StepBuilder
step(FaultyStep)
step FaultyStep
end

defmodule FaultyFunctionStep do
use Pluggable.StepBuilder
step(:faulty_function)
step :faulty_function

# Doesn't return a Pluggable.Token
def faulty_function(_token, _opts), do: "foo"
Expand Down Expand Up @@ -137,7 +137,7 @@ defmodule Pluggable.StepBuilderTest do
end

use Pluggable.StepBuilder
step(Bad)
step Bad
end
end
end
Expand All @@ -157,14 +157,14 @@ defmodule Pluggable.StepBuilderTest do
use Pluggable.StepBuilder

var = :plug_init
step(Assigner, var)
step Assigner, var
end

defmodule RuntimeInit do
use Pluggable.StepBuilder, init_mode: :runtime

var = :plug_init
step(Assigner, var)
step Assigner, var
end

:ok = Agent.update(:plug_init, fn :compile -> :runtime end)
Expand All @@ -186,13 +186,13 @@ defmodule Pluggable.StepBuilderTest do
defmodule LogOnModuleHalt do
use Pluggable.StepBuilder, log_on_halt: :error

step(Halter)
step Halter
end

defmodule LogOnFunctionHalt do
use Pluggable.StepBuilder, log_on_halt: :error

step(:halter)
step :halter

def halter(token, _opts), do: halt(token)
end
Expand Down

0 comments on commit 6061fe3

Please sign in to comment.