StrictLayout not honoring guard rules
Credo is not emitting any suggestion
.credo.exs
{Credo.Check.Readability.StrictModuleLayout,
order: [
:moduledoc,
:public_guard,
:private_guard
]}
module
defguardp is_foo(term) when term == :foo
defguard is_bar(term) when term == :bar
I have used Credo v1.7 and master.
A sample repo that reproduces this can be found here: https://github.com/eksperimental-debug/credo_debug/tree/strict-layout-guards
Thanks for reporting this 😀 It should be 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! 👍
Thank for the fix. Unfortunately I am getting the following message in a module with no defp defined.
[R] ↘ public guard must appear before private_guard
The line refers to the last public guard defined in the module.
I was not able to reproduce this with this module:
# order: [:moduledoc, :public_guard, :private_guard]
defmodule Test do
@moduledoc ""
defguard is_bar(term) when term == :bar
defguard is_baz(term) when not is_foo(term) and term == :baz
end
Could you provide a snippet that reproduces this?
Hi Rene. Thank you for looking into this.
I think it is mistaking a hidden guard (public guard with @doc false) for a private guard.
Here's a snippet that reproduces it.
defmodule Test do
@moduledoc ""
@doc false
defguard is_bar(term) when term == :bar
defguard is_baz(term) when not is_bar(term) and term == :baz
end
Yes, undocumented guards, functions and macros are treated as "private". This was a choice by the original author of the check.
We could add a parameter to disable this behaviour, of course.