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

unquote piped into unquote results in invalid unquote/2 invocation #51

Closed
elliottneilclark opened this issue Jun 13, 2023 · 5 comments
Closed
Labels
wontfix This will not be worked on

Comments

@elliottneilclark
Copy link

Versions

  • Elixir: Elixir 1.14.5 (compiled with Erlang/OTP 25)
  • Styler: locked at 0.7.12 (styler) 9b309b7c

Example Input

  defp pipe(left, right) do
    quote do
      unquote(left) |> unquote(right)
    end
  end

Stacktrace / Current Behaviour

That produces:

  defp pipe(left, right) do
    quote do
      unquote(unquote(left), right)
    end
  end
@novaugust
Copy link
Contributor

Heya, thanks for the issue.

This doesn't look like something we'll fix in Styler. Sometimes when it makes kaboomy code, it's a good chance to zoom out and see if things can just be written different -- kind of like when the formatter makes code look weird.

In this case, I'd suggest using bind_quoted to remove the use of unquote. At that point, Styler would rewrite left |> right as just right(left), and your code will be just that little bit happier.

@novaugust novaugust added the wontfix This will not be worked on label Jun 13, 2023
@novaugust novaugust changed the title Styler produces invalid changes in quoted code unquote piped into unquote results in invalid unquote/2 invocation Jun 13, 2023
@elliottneilclark
Copy link
Author

elliottneilclark commented Jun 13, 2023

In this case, I'd suggest using bind_quoted to remove the use of unquote.

That's not possible in the place that I extracted the code from, but I understand your point of there are other ways to write this. (this is from code generation path that produces code from a Macro.to_string and the final format is more important so it's unsual) I still think this is worth solving by ignoring code in quote.

From experience with black/clang-format on large code bases I can tell you that you need to either focus on never producing broken code, or allow configuring styler in specific cases. #noqa or the like. The project README shows this already becoming apparent. There are a number of gotchas around styler making incorrect changes. You can't turn those checks off like you can with credo, and you have to manually fix them.

TLDR: You should follow Linus' golden rule:

You Do Not Break Userspace

@novaugust
Copy link
Contributor

thanks for the input elliott, but having styler style code inside of quote is quite intentional - we like to keep all our code consistent. that said, we're very supportive of people forking the library and making the tool their own.

@novaugust
Copy link
Contributor

while we don't want to disable styler in quotes, making it work with the idea that some unquote usages only work with a preceding pipe is good style, if you will. got it fixed on main, thanks

@elliottneilclark
Copy link
Author

having styler style code inside of quote is quite intentional

Totally, that was simply the easiest tactical fix I could see, since creating quoted piped code wasn't that common. Thanks for the even better solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants