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

Warn on unsupported arguments in contents, index, autodocs, and meta blocks #2324

Merged
merged 5 commits into from
Nov 12, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* `id` anchors may now start with a numeric digit. ([#744], [#2325])
* Documenter prints a more informative warning now if there is unexpected Julia interpolation in the Markdown (e.g. from errant `$` signs). ([#2288], [#2327])
* Documenter now warns when it encounters invalid keys in the various key-value at-blocks. ([#2306], [#2324])

### Fixed

Expand Down
14 changes: 14 additions & 0 deletions src/documents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
source = error("missing value for `source` in `IndexNode`."),
others...
)
if !isempty(others)
@warn(

Check warning on line 100 in src/documents.jl

View check run for this annotation

Codecov / codecov/patch

src/documents.jl#L99-L100

Added lines #L99 - L100 were not covered by tests
"In file $source: the following unsupported keyword " *
"arguments have been set in the `@index` node:\n" *
join([string(k, " = ", v) for (k, v) in others], "\n"),
)
end
new(Pages, Modules, Order, build, source, [], codeblock)
end
end
Expand All @@ -121,6 +128,13 @@
if Depth isa Integer
Depth = 1:Depth
end
if !isempty(others)
@warn(

Check warning on line 132 in src/documents.jl

View check run for this annotation

Codecov / codecov/patch

src/documents.jl#L131-L132

Added lines #L131 - L132 were not covered by tests
"In file $source: the following unsupported keyword " *
"arguments have been set in the `@contents` node:\n" *
join([string(k, " = ", v) for (k, v) in others], "\n"),
)
end
new(Pages, first(Depth), last(Depth), build, source, [], codeblock)
end
end
Expand Down
18 changes: 17 additions & 1 deletion src/expander_pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,17 @@
lines = Documenter.find_block_in_file(x.code, page.source)
@debug "Evaluating @meta block:\n$(x.code)"
for (ex, str) in Documenter.parseblock(x.code, doc, page)
# If not `isassign`, this might be a comment, or any code that the user
# wants to hide. We should probably warn, but it is common enough that
# we will silently skip for now.
if Documenter.isassign(ex)
if !(ex.args[1] in (:Currentmodule, :DocTestSetup, :DocTestFilters, :EditURL, :Description, :Draft))
source = Documenter.locrepr(page.source, lines)
@warn(

Check warning on line 298 in src/expander_pipeline.jl

View check run for this annotation

Codecov / codecov/patch

src/expander_pipeline.jl#L296-L298

Added lines #L296 - L298 were not covered by tests
"In $source: `@meta` block has an unsupported " *
"keyword argument: $(ex.args[1])",
)
end
try
meta[ex.args[1]] = Core.eval(Main, ex.args[2])
catch err
Expand Down Expand Up @@ -460,8 +470,14 @@
try
if ex.args[1] == :Filter
fields[ex.args[1]] = Core.eval(Main, ex.args[2])
else
elseif ex.args[1] in (:Modules, :Order, :Pages, :Public, :Private)

Check warning on line 473 in src/expander_pipeline.jl

View check run for this annotation

Codecov / codecov/patch

src/expander_pipeline.jl#L473

Added line #L473 was not covered by tests
fields[ex.args[1]] = Core.eval(curmod, ex.args[2])
else
source = Documenter.locrepr(page.source, lines)
@warn(

Check warning on line 477 in src/expander_pipeline.jl

View check run for this annotation

Codecov / codecov/patch

src/expander_pipeline.jl#L476-L477

Added lines #L476 - L477 were not covered by tests
"In $source: `@autodocs` block has an unsupported " *
"keyword argument: $(ex.args[1])",
)
end
catch err
@docerror(doc, :autodocs_block,
Expand Down
10 changes: 10 additions & 0 deletions test/errors/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ parse error

```@meta
CurrentModule = NonExistentModule
draft = true # invalid keyword
```

```@autodocs
Modules = [NonExistentModule]
pages = [] # invalid keyword
```

```@eval
Expand All @@ -23,6 +25,14 @@ NonExistentModule
# comment in a @docs block
```

```@index
foo = 1
```

```@contents
foo = 1
```

[`foo(x::Foo)`](@ref) creates an [`UndefVarError`](@ref) when `eval`d
for the type signature, since `Foo` is not defined.

Expand Down
Loading