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

The mix format process being hung up while one of the if statements body is empty #196

Closed
itamm15 opened this issue Sep 21, 2024 · 1 comment

Comments

@itamm15
Copy link

itamm15 commented Sep 21, 2024

Versions

  • Elixir: 1.17
  • Styler:1.0.0

Example Input

defmodule StylerError.ErrorCase do
  def test do
    a = 1
    b = 2

    if a != b do
      # TODO: handle this case
    else
      :ok
    end
  end
end

Stacktrace / Current Behaviour

Without having the Styler passed in the .formatter.exs file (see itamm15/elixir-styler-error-repo@bb3b83c);

image

With Styler passed in the .formatter.exs file (see itamm15/elixir-styler-error-repo@d37a4eb);

image

(I waited for about 10 minutes, but nothing happened)

But when I explicitly set the nil in the first statement body;

image

It works! (Styler just removed that case, and moved the comment to the else body), previously with nil before Styler change;

    if a != b do
      # TODO: handle this case
      nil
    else
      :ok
    end

I created a repo for that https://github.com/itamm15/elixir-styler-error-repo, and there is an example test file https://github.com/itamm15/elixir-styler-error-repo/blob/master/lib/styler_error/error_case.ex

(Thanks for that lib, and hopefully I haven't missed anything in the docs, that this is an expected scenario 😄)

@itamm15 itamm15 changed the title Process being hung up while one of the if statements body is empty The mix format process being hung up while one of the if statements body is empty Sep 22, 2024
@novaugust
Copy link
Contributor

thanks for the report @itamm15, have it fixed on main / will be out in 1.1 =)

emkguts added a commit to smartrent/elixir-styler that referenced this issue Sep 24, 2024
* fix infinite loop rewriting negated if with empty do body. closes adobe#196

* Remove unless from codebases (adobe#194)

* use `not` over `!` when rewriting `unless a (> >= < <= in) b`

* actually, lets only do `not` for `in`

* v1.1.0

* update version in readme

* Don't pipe into `Kernel.!` when rewriting unless with pipes

---------

Co-authored-by: Matt Enlow <enlow@adobe.com>
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

No branches or pull requests

2 participants