Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with handling seems to be broken in 0.11.0 #107

Closed
kerryb opened this issue Dec 12, 2023 · 7 comments · Fixed by #108
Closed

with handling seems to be broken in 0.11.0 #107

kerryb opened this issue Dec 12, 2023 · 7 comments · Fixed by #108

Comments

@kerryb
Copy link

kerryb commented Dec 12, 2023

Versions

  • Elixir: 1.15.7
  • Styler: 0.11.0

Example Input

defmodule Foo do
  @moduledoc false
  def run(arg) do
    with value <- arg do
      value
    end
  end
end

Stacktrace / Current Behaviour

foo$ mix format
** (Styler.StyleError) Error running style Blocks on lib/foo.ex
   Please consider opening an issue at: https://github.com/adobe/elixir-styler/issues/new
** (RuntimeError) unexpected `with` parent ast: {{:__block__, [line: 3], [:do]}, {:with, [do: [line: 4], end: [line: 6], line: 4], [{:<-, [line: 4], [{:value, [line: 4], nil}, {:arg, [line: 4], nil}]}, [{{:__block__, [line: 4], [:do]}, {:value, [line: 5], nil}}]]}}

    (styler 0.11.0) lib/style/blocks.ex:220: Styler.Style.Blocks.replace_with_statement/2
    (styler 0.11.0) lib/style/blocks.ex:79: Styler.Style.Blocks.run/2
    (styler 0.11.0) lib/zipper.ex:367: Styler.Zipper.do_traverse_while/3
    (styler 0.11.0) lib/styler.ex:37: anonymous fn/4 in Styler.style/3
    (elixir 1.15.7) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
    (styler 0.11.0) lib/styler.ex:35: Styler.style/3
    (styler 0.11.0) lib/styler.ex:65: Styler.format/3
    (elixir 1.15.7) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3

Skipping style and continuing on
@novaugust
Copy link
Contributor

kerry nooo! just when i thought i'd thought of it all. thanks for the minimal repro, will have it fixed in a jiffy.

@novaugust
Copy link
Contributor

(just to be clear, this is only blowing up when we're trying to delete a with statement that has no pattern matching and so could've been written as just plain code, which is also the sole child of a function -- i didn't break all with handling 😂 )

@kerryb
Copy link
Author

kerryb commented Dec 12, 2023

(just to be clear, this is only blowing up when we're trying to delete a with statement that has no pattern matching and so could've been written as just plain code, which is also the sole child of a function -- i didn't break all with handling 😂 )

Sadly it turns out that antipattern cropped up several times in my code 🙄

@novaugust
Copy link
Contributor

novaugust commented Dec 12, 2023

my heart goes out to you.
i've got the fix for the "unexpected ast" kaboomy, just seeing if i can easily get it to replace your exact snippet with just arg rather than value = arg\nvalue

@novaugust
Copy link
Contributor

novaugust commented Dec 12, 2023

@kerryb any chance you'd be interested in running main against your codebase to see if there's anything else i should get in before releasing 11.1 on hex?
i believe the syntax for using github is as follows:

# mix.exs
- {:styler, "~> 0.11"},
+ {:styler, github: "adobe/elixir-styler"},

@kerryb
Copy link
Author

kerryb commented Dec 12, 2023

Just tried it, and my withs have been tidied up with no issues :-)

Thanks for the quick fix!

@novaugust
Copy link
Contributor

cheers, 0.11.1 is on hex. hope you like your codebase just that little bit more now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants