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

include macros in Docs.undocumented_names #52727

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,16 @@ end
Return an array of undocumented symbols in `module` (that is, lacking docstrings).
`all=false` returns only exported symbols; whereas `all=true` also includes
non-exported symbols, following the behavior of [`names`](@ref). Only valid identifiers
are included. Names are returned in sorted order.
and `@macro` symbols are included. Names are returned in sorted order.

See also: [`names`](@ref), [`Docs.hasdoc`](@ref), [`Base.isidentifier`](@ref).
"""
function undocumented_names(mod::Module; all::Bool=false)
filter!(names(mod; all)) do sym
!hasdoc(mod, sym) && Base.isidentifier(sym)
!hasdoc(mod, sym) && (Base.isidentifier(sym) ||
let str = string(sym)
startswith(str, '@') && Base.isidentifier(str[2:end])
end)
end
end

Expand Down
5 changes: 3 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ function break_me_docs end

"This module has names without documentation."
module _ModuleWithUndocumentedNames
export f
export f, @foo
f() = 1
macro foo(); end
end

"This module has some documentation."
Expand All @@ -90,7 +91,7 @@ f() = 1
g() = 2
end

@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [:f]
@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [Symbol("@foo"), :f]
@test isempty(Docs.undocumented_names(_ModuleWithSomeDocumentedNames))
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; all=true) == [:eval, :g, :include]

Expand Down