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

Add Docs.undocumented_names #52413

Merged
merged 17 commits into from
Dec 31, 2023
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ New library features
write the output to a stream rather than returning a string ([#48625]).
* `sizehint!(s, n)` now supports an optional `shrink` argument to disable shrinking ([#51929]).
* New function `Docs.hasdoc(module, symbol)` tells whether a name has a docstring ([#52139]).
* New function `Docs.check_documented(module; all)` checks whether a module's names are documented ([#52413]).
* New function `Docs.undocumented_names(module; all)` returns a module's undocumented names ([#52413]).

Standard library changes
------------------------
Expand Down
13 changes: 7 additions & 6 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,15 @@ end


"""
check_documented(mod::Module; all=false)
undocumented_names(mod::Module; all=false)
jariji marked this conversation as resolved.
Show resolved Hide resolved

Check all names in the module are documented. `all` determines which names are checked,
following the behavior of `names(mod; all)`.
Return the undocumented names in `module`. `all=false` returns only public names;
`all=true` also includes nonpublic names, following the behavior of [`names`](@ref).
jariji marked this conversation as resolved.
Show resolved Hide resolved

See also: [`names`](@ref), [`Docs.hasdoc`](@ref).
"""
function check_documented(mod::Module; all=false)
nodocs = filter!(sym -> !hasdoc(mod, sym), names(mod; all))
isempty(nodocs) || error("missing docstrings in $mod: $nodocs")
function undocumented_names(mod::Module; all=false)
filter(!hasdoc, names(mod; all))
end
jariji marked this conversation as resolved.
Show resolved Hide resolved

end
4 changes: 2 additions & 2 deletions doc/src/manual/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ environments provide a way to access documentation directly:
under the cursor.


`Docs.hasdoc(module, name)::Bool` tells whether a name has a docstring. `Docs.check_documented(module; all)`
checks that the names in a module are documented.
`Docs.hasdoc(module, name)::Bool` tells whether a name has a docstring. `Docs.undocumented_names(module; all)`
returns the undocumented names in a module.
jariji marked this conversation as resolved.
Show resolved Hide resolved

## Writing Documentation

Expand Down
9 changes: 3 additions & 6 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ f() = 1
g() = 2
end

# Error for undocumented names.
@test_throws ErrorException Docs.check_documented(_ModuleWithUndocumentedNames)
# Pass for documented exported names.
@test Docs.check_documented(_ModuleWithSomeDocumentedNames)
# Error for undocumented unexported names when `all=true`.
@test_throws ErrorException Docs.check_documented(_ModuleWithSomeDocumentedNames; all=true)
@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [:f]
@test isempty(Docs.undocumented_names(_ModuleWithSomeDocumentedNames))
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; all=true) == [:g]
jariji marked this conversation as resolved.
Show resolved Hide resolved


# issue #11548
Expand Down