elixir-lang / ex_doc

ExDoc produces HTML and EPUB documentation for Elixir projects
http://elixir-lang.org
Other
1.43k stars 325 forks source link

More explicit warning when type not visible because module is not visible #1932

Closed axelson closed 1 week ago

axelson commented 1 month ago

Recently I was working on one of my libraries (https://github.com/axelson/password-validator commit 4bb73) and I received the following warning:

> mix docs
Generating docs...
    warning: documentation references type "PasswordValidator.Validators.CharacterSetValidator.Config.t()" but it is hidden or private
    │
 79 │     def validate_character_set(
    │     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ (password_validator 0.5.1) lib/password_validator/validators/character_set_validator.ex:79: PasswordValidator.Validators.CharacterSetValidator.validate_character_set/3

I was initially surprised because IEx the type exists and is public (i.e. @type instead of @typep) and IEx finds the type just fine:

iex(2)> t PasswordValidator.Validators.CharacterSetValidator.Config.t
@type t() :: %PasswordValidator.Validators.CharacterSetValidator.Config{
        allowed_special_characters: :all | String.t() | nil,
        custom_messages: any(),
        lower_case: [:infinity | non_neg_integer()],
        numbers: [:infinity | non_neg_integer()],
        special: [:infinity | non_neg_integer()],
        upper_case: [:infinity | non_neg_integer()]
      }

After a good bit of head scratching I finally realized that the issue was that the module (not the type) was hidden via @moduledoc false

Coming back to the error message "documentation references type "PasswordValidator.Validators.CharacterSetValidator.Config.t()" but it is hidden or private" I think I thought that the it in the sentence was referring to the type, but it is really referring to the module, or maybe the message isn't explicit/obvious that the type isn't visible because the module isn't visible.

My suggested updated warning message would be "warning: documentation references type "PasswordValidator.Validators.CharacterSetValidator.Config.t()" but the module PasswordValidator.Validators.CharacterSetValidator.Config is hidden or private".

josevalim commented 1 month ago

Yes, it would be a welcome improvement for sure. A PR is welcome!

josevalim commented 1 week ago

Closing in favor of the PR!