-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
docsystemThe documentation building systemThe documentation building systemfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requestsgood first issueIndicates a good issue for first-time contributors to JuliaIndicates a good issue for first-time contributors to JuliatestsystemThe unit testing framework and Test stdlibThe unit testing framework and Test stdlib
Description
As discussed on discourse, it would be nice to have a (documented) way to test whether all exported symbols in a module have docstrings. Currently, this seems to require undocumented internals?
Something like:
# hasdoc should go in Base.Docs; might also be accomplished by refactoring Base.Docs.doc somehow
using Base.Docs: Binding, defined, getdoc, resolve, meta, modules, aliasof
hasdoc(mod::Module, sym::Symbol) = hasdoc(Base.Docs.Binding(mod, sym))
function hasdoc(binding::Binding, sig::Type = Union{})
defined(binding) && !isnothing(getdoc(resolve(binding), sig)) && return true
for mod in modules
dict = meta(mod; autoinit=false)
!isnothing(dict) && haskey(dict, binding) && return true
end
alias = aliasof(binding)
return alias == binding ? false : hasdoc(alias, sig)
end
# possible function for the Test module
function check_documented(mod::Module)
nodocs = filter!(sym -> !hasdoc(mod, sym), names(mod))
isempty(nodocs) || error("missing docstrings in $mod: $nodocs")
endFor example, this catches some missing docstrings in Base and several standard libraries:
julia> check_documented(Base)
ERROR: missing docstrings in Base: [:CanonicalIndexError, :CapturedException, :InvalidStateException]
julia> check_documented(LinearAlgebra)
ERROR: missing docstrings in LinearAlgebra: [:ColumnNorm, :LAPACKException, :NoPivot, :RankDeficientException, :RowMaximum, :RowNonZero, :copy_transpose!]
julia> check_documented(Markdown)
ERROR: missing docstrings in Markdown: [Symbol("@doc_str"), Symbol("@md_str"), :html, :latex]
julia> check_documented(Pkg)
ERROR: missing docstrings in Pkg: [Symbol("@pkg_str"), :PKGMODE_MANIFEST, :PKGMODE_PROJECT, :PRESERVE_ALL, :PRESERVE_ALL_INSTALLED, :PRESERVE_DIRECT, :PRESERVE_NONE, :PRESERVE_SEMVER, :PRESERVE_TIERED, :PRESERVE_TIERED_INSTALLED, :Pkg, :PreserveLevel, :Registry, :UPLEVEL_MAJOR, :UPLEVEL_MINOR, :UPLEVEL_PATCH]ericphanson, ffevotte, timholy, laborg, jariji and 5 more
Metadata
Metadata
Assignees
Labels
docsystemThe documentation building systemThe documentation building systemfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requestsgood first issueIndicates a good issue for first-time contributors to JuliaIndicates a good issue for first-time contributors to JuliatestsystemThe unit testing framework and Test stdlibThe unit testing framework and Test stdlib