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

False negative: Nested blocks inside an if/else clause are not detected #1029

Closed
oeken opened this issue Feb 28, 2023 · 5 comments
Closed

False negative: Nested blocks inside an if/else clause are not detected #1029

oeken opened this issue Feb 28, 2023 · 5 comments

Comments

@oeken
Copy link

oeken commented Feb 28, 2023

Environment

Credo version: 1.6.7
Erlang/Elixir version:

Erlang/OTP 25 [erts-13.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]
Elixir 1.14.3 (compiled with Erlang/OTP 25)

Operating system: macos M1

What were you trying to do?

Identify deeply nested functions. I used mix credo --all with default configuration. It successfully identified many. However missed functions of the following form.

defp foo() do
  if true do
    if true do
      if true do
        if true do
          "nested"
        end
      end
    end
  else
    "flat"
  end
end

Note: If I omit the else block then the suggestion is raised.

Expected outcome

Raise suggestion: Function body is nested too deep (max depth is 2, was 4).

Actual outcome

Credo found no issues.

rrrene added a commit that referenced this issue Mar 2, 2023
rrrene added a commit that referenced this issue Mar 2, 2023
@rrrene
Copy link
Owner

rrrene commented Mar 2, 2023

Thanks for reporting this 😀 It is now fixed on master.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! 👍

@oeken
Copy link
Author

oeken commented Mar 3, 2023

Yes! Thank you for speedy fix 🚀

@oeken oeken closed this as completed Mar 3, 2023
@oeken
Copy link
Author

oeken commented Mar 3, 2023

Reopening because the code change indeed addresses nesting inside if blocks but not inside else blocks. e.g.

defp foo() do
  if true do
    "flat"
  else
    if true do
      if true do
        if true do
          "nested"
        end
      end
    end
  end
end

could you take a look? 👀 thank you 🙏🏻

@oeken oeken reopened this Mar 3, 2023
rrrene added a commit that referenced this issue Mar 3, 2023
@rrrene
Copy link
Owner

rrrene commented Mar 3, 2023

D'oh! Just pushed another fix. Could you try again?

@oeken
Copy link
Author

oeken commented Oct 25, 2023

Coming back here ages later again - but thanks a lot! works as expected 🚀

@oeken oeken closed this as completed Oct 25, 2023
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