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

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

Closed
axelson opened this issue Jul 14, 2024 · 2 comments · Fixed by #1940
Closed

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

axelson opened this issue Jul 14, 2024 · 2 comments · Fixed by #1940

Comments

@axelson
Copy link
Contributor

axelson commented Jul 14, 2024

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
Copy link
Member

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

voughtdq added a commit to voughtdq/ex_doc that referenced this issue Aug 12, 2024
Closes elixir-lang#1932
When a module is hidden, its types will also be hidden. We check for two
conditions and warn the user if both are met:
 - The module defining the type is hidden
 - The type itself is hidden
If the type is undefined, the standard warning is displayed instead.
@josevalim
Copy link
Member

Closing in favor of the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants