How to remove waring "Modules should have a @moduledoc tag" - mix credo -a

I am using mix credo -a to check code readably. But I am getting multiple message as “Modules should have a @moduledoc tag.” I am not sure how to suppress/remove this.
Thanks in advance for any kind of help.

Sometimes when you are not sure about how to solve an issue, you can use mix credo explain, and it will tell you something about the suggestion and how to resolve it.

The simplest way though to solve your issue at hand is, to simply document the modules that have this issue: @moduledoc

1 Like

Thanks @NobbZ for your help. I’ll try this and hope this will solve my issue.

1 Like

Or you could just document your modules :wink:

3 Likes

Yes, that seems to be the actual reason of this warning. :slight_smile: Thanks.

That command alone will not solve anything, its just that it might give you some more in depth explanation of an issue.

To solve the actual issue, you need to use @moduledoc do document your modules, as I already said earlier.

1 Like

You can add @moduledoc false and credo will skip the module’s documentation, not showing the warning.

2 Likes

This will also specifically prevent the module from even being listed in generation documentation and some other lookups as well.

3 Likes

For who like me doesn’t want to open all files one by one and type that:

#!/bin/bash

# acting on all files under lib/
IFS=$'\n'
SUBB='Modules should have a @moduledoc tag.'

for line in $(mix credo list --format oneline)
do
   if [[ "$line" == *"$SUBB"* ]]; then
      path_to_file=$(echo "$line" | grep -P '((lib)+[\/a-z0-9._]+)+(\/?){1}' -o)

      sed -i '2 i\  @moduledoc false\n' $path_to_file
   fi
done

The separator is 2 whitespaces (others prefer tabs)
it gets all files under lib

1 Like

Add this to your .credo.exs file:

{Credo.Check.Readability.ModuleDoc, false}

Put a false near to the Credo.Check.Readability.ModuleDoc

This would disable checks for module docs.