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

Readability checks fail for shorthand module definitions #966

Closed
jjcarstens opened this issue Apr 14, 2022 · 2 comments
Closed

Readability checks fail for shorthand module definitions #966

jjcarstens opened this issue Apr 14, 2022 · 2 comments

Comments

@jjcarstens
Copy link

Environment

  • Credo version (mix credo -v): 1.6.4
  • Erlang/Elixir version (elixir -v): 1.13.3 OTP 24.3.3
  • Operating system: MacOS 12.3

What were you trying to do?

This might be totally out of scope, but I find it interesting non-the-less.

I have a really simple one-liner module definition in a file. Something like

defmodule Person, do: def greet(), do: :howdy

Technically valid Elixir (arguably code smell 🥴 ), and it crashes during Elixir.Credo.Check.Readability.* checks.

Log output
> firmware √ % mix credo                                                                                                                                                                                                                               CB-87-test-firmware
Checking 26 source files ...
Error while running Elixir.Credo.Check.Readability.Specs on test/support/test.ex
Error while running Elixir.Credo.Check.Readability.ModuleDoc on test/support/test.ex

14:38:15.333 [error] Task #PID<0.498.0> started from #PID<0.395.0> terminating
** (ArithmeticError) bad argument in arithmetic expression
    :erlang.+(1, nil)
    (credo 1.6.4) lib/credo/priority.ex:83: anonymous fn/2 in Credo.Priority.scope_priorities/1
    (elixir 1.13.3) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.13.3) lib/enum.ex:1496: Enum.into/3
    (credo 1.6.4) lib/credo/check.ex:714: Credo.Check.priority_for/2
    (credo 1.6.4) lib/credo/check.ex:654: Credo.Check.add_line_no_options/3
    (credo 1.6.4) lib/credo/check.ex:624: Credo.Check.format_issue/5
    (credo 1.6.4) lib/credo/check/readability/module_doc.ex:87: Credo.Check.Readability.ModuleDoc.traverse/4
Function: #Function<5.41562928/0 in Credo.Check.Readability.ModuleDoc.do_run_on_all_source_files/3>
    Args: []

14:38:15.333 [error] Task #PID<0.1815.0> started from #PID<0.1763.0> terminating
** (ArithmeticError) bad argument in arithmetic expression
    :erlang.+(1, nil)
    (credo 1.6.4) lib/credo/priority.ex:83: anonymous fn/2 in Credo.Priority.scope_priorities/1
    (elixir 1.13.3) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.13.3) lib/enum.ex:1496: Enum.into/3
    (credo 1.6.4) lib/credo/check.ex:714: Credo.Check.priority_for/2
    (credo 1.6.4) lib/credo/check.ex:654: Credo.Check.add_line_no_options/3
    (credo 1.6.4) lib/credo/check.ex:624: Credo.Check.format_issue/5
    (credo 1.6.4) lib/credo/check/readability/specs.ex:104: Credo.Check.Readability.Specs.traverse/4
Function: #Function<5.24813483/0 in Credo.Check.Readability.Specs.do_run_on_all_source_files/3>
    Args: []
** (EXIT from #PID<0.93.0>) an exception was raised:
    ** (ArithmeticError) bad argument in arithmetic expression
        :erlang.+(1, nil)
        (credo 1.6.4) lib/credo/priority.ex:83: anonymous fn/2 in Credo.Priority.scope_priorities/1
        (elixir 1.13.3) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
        (elixir 1.13.3) lib/enum.ex:1496: Enum.into/3
        (credo 1.6.4) lib/credo/check.ex:714: Credo.Check.priority_for/2
        (credo 1.6.4) lib/credo/check.ex:654: Credo.Check.add_line_no_options/3
        (credo 1.6.4) lib/credo/check.ex:624: Credo.Check.format_issue/5
        (credo 1.6.4) lib/credo/check/readability/specs.ex:104: Credo.Check.Readability.Specs.traverse/4

Oddly enough, I can successfully get past it by actually including the moduledoc

defmodule Test, do: @moduledoc "why though?!"; def test(), do: :howdy

I don't even know if I would call this a bug or expect a fix, so do what you will with this issue. It's at least interesting and maybe useful for posterity 😉

@rrrene
Copy link
Owner

rrrene commented Apr 15, 2022

Judging from the log, this might actually highlight a deeper issue.

Thx for reporting! 👍

@rrrene
Copy link
Owner

rrrene commented Jul 31, 2022

Thx for reporting this! 👍 It should be be fixed in the latest version of Credo.

If it is not, please feel free to re-open this issue!

@rrrene rrrene closed this as completed Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants