Skip to content

Commit

Permalink
mix format :X
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Nov 23, 2024
1 parent 411cc93 commit b13d045
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/style.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule Styler.Style do

@doc "sorts a list of nodes according to their string representations"
def sort(ast, opts \\ []) when is_list(ast) do
format = if opts[:format] == :downcase, do: &String.downcase/1, else: &(&1)
format = if opts[:format] == :downcase, do: &String.downcase/1, else: & &1

ast
|> Enum.map(&{&1, &1 |> Macro.to_string() |> format.()})
Expand Down
2 changes: 1 addition & 1 deletion lib/style/comment_directives.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Styler.Style.CommentDirectives do
end)

if found do
#@TODO fix line numbers, move comments
# @TODO fix line numbers, move comments
Zipper.update(found, &sort/1)
else
zipper
Expand Down
41 changes: 22 additions & 19 deletions test/style/comment_directives_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,28 @@ defmodule Styler.Style.CommentDirectivesTest do
test "list of tuples" do
# 2ples are represented as block literals while >2ples are created via `:{}`
# decided the easiest way to handle this is to just use string representation for meow
assert_style """
# styler:sort
[
{:styler, github: "adobe/elixir-styler"},
{:ash, "~> 3.0"},
{:fluxon, "~> 1.0.0", repo: :fluxon},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
]
""","""
# styler:sort
[
{:ash, "~> 3.0"},
{:fluxon, "~> 1.0.0", repo: :fluxon},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:styler, github: "adobe/elixir-styler"},
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
]
"""
assert_style(
"""
# styler:sort
[
{:styler, github: "adobe/elixir-styler"},
{:ash, "~> 3.0"},
{:fluxon, "~> 1.0.0", repo: :fluxon},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
]
""",
"""
# styler:sort
[
{:ash, "~> 3.0"},
{:fluxon, "~> 1.0.0", repo: :fluxon},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:styler, github: "adobe/elixir-styler"},
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
]
"""
)
end
end
end

0 comments on commit b13d045

Please sign in to comment.