Skip to content

Commit bc809d5

Browse files
committed
warn-no-paramdoc option
#feat
1 parent bc7bd3a commit bc809d5

File tree

14 files changed

+126
-19
lines changed

14 files changed

+126
-19
lines changed

docs/mrdocs.schema.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,24 @@
462462
},
463463
"warn-if-undocumented": {
464464
"default": true,
465-
"description": "When set to `true`, MrDocs outputs a warning message if a symbol that passes all filters is not documented. This option is only effective when `extract-all` is set to `false`.",
465+
"description": "When set to `true`, MrDocs outputs a warning message if a symbol that passes all filters is not documented.",
466466
"enum": [
467467
true,
468468
false
469469
],
470470
"title": "Warn if symbols are not documented",
471471
"type": "boolean"
472472
},
473+
"warn-no-paramdoc": {
474+
"default": true,
475+
"description": "When set to `true`, MrDocs outputs a warning message if a named function parameter is not documented.",
476+
"enum": [
477+
true,
478+
false
479+
],
480+
"title": "Warn if parameters are not documented",
481+
"type": "boolean"
482+
},
473483
"warnings": {
474484
"default": true,
475485
"description": "When set to `true`, MrDocs outputs warning messages during the generation of the documentation. It is usually recommended to enable warnings while writing the documentation.",

src/lib/Lib/ConfigOptions.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
{
483483
"name": "warn-if-undocumented",
484484
"brief": "Warn if symbols are not documented",
485-
"details": "When set to `true`, MrDocs outputs a warning message if a symbol that passes all filters is not documented. This option is only effective when `extract-all` is set to `false`.",
485+
"details": "When set to `true`, MrDocs outputs a warning message if a symbol that passes all filters is not documented.",
486486
"type": "bool",
487487
"default": true
488488
},
@@ -492,6 +492,13 @@
492492
"details": "When set to `true`, MrDocs outputs a warning message if the documentation of a symbol has errors such as duplicate parameters and parameters that don't exist.",
493493
"type": "bool",
494494
"default": true
495+
},
496+
{
497+
"name": "warn-no-paramdoc",
498+
"brief": "Warn if parameters are not documented",
499+
"details": "When set to `true`, MrDocs outputs a warning message if a named function parameter is not documented.",
500+
"type": "bool",
501+
"default": true
495502
}
496503
]
497504
},

src/lib/Metadata/Finalizers/JavadocFinalizer.cpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ operator()(InfoTy& I)
105105
}
106106
}
107107

108-
#define INFO(T) template void JavadocFinalizer::operator()<T##Info>(T##Info&);
108+
#define INFO(T) template void JavadocFinalizer::operator()<T## Info>(T## Info&);
109109
#include <mrdocs/Metadata/InfoNodesPascal.inc>
110110

111111
void
@@ -516,13 +516,13 @@ emitWarnings() const
516516
MRDOCS_CHECK_OR(corpus_.config->warnings);
517517
warnUndocumented();
518518
warnDocErrors();
519+
warnNoParamDocs();
519520
}
520521

521522
void
522523
JavadocFinalizer::
523524
warnUndocumented() const
524525
{
525-
MRDOCS_CHECK_OR(!corpus_.config->extractAll);
526526
MRDOCS_CHECK_OR(corpus_.config->warnIfUndocumented);
527527
for (auto& [id, name] : corpus_.undocumented_)
528528
{
@@ -599,10 +599,49 @@ warnParamErrors(FunctionInfo const& I) const
599599
}
600600
javadocParamNames.erase(lastUnique, javadocParamNames.end());
601601

602+
// Check for documented parameters that don't exist in the function
603+
auto paramNames =
604+
std::views::transform(I.Params, &Param::Name) |
605+
std::views::filter([](std::string_view const& name) { return !name.empty(); });
606+
for (std::string_view javadocParamName: javadocParamNames)
607+
{
608+
if (std::ranges::find(paramNames, javadocParamName) == paramNames.end())
609+
{
610+
auto primaryLoc = getPrimaryLocation(I);
611+
warn(
612+
"{}:{}\n"
613+
"{}: Documented parameter '{}' does not exist",
614+
primaryLoc->FullPath,
615+
primaryLoc->LineNumber,
616+
corpus_.Corpus::qualifiedName(I),
617+
javadocParamName);
618+
}
619+
}
620+
621+
}
622+
623+
void
624+
JavadocFinalizer::
625+
warnNoParamDocs() const
626+
{
627+
MRDOCS_CHECK_OR(corpus_.config->warnNoParamdoc);
628+
for (auto const& I : corpus_.info_)
629+
{
630+
MRDOCS_CHECK_OR_CONTINUE(I->Extraction == ExtractionMode::Regular);
631+
MRDOCS_CHECK_OR_CONTINUE(I->isFunction());
632+
MRDOCS_CHECK_OR_CONTINUE(I->javadoc);
633+
warnNoParamDocs(dynamic_cast<FunctionInfo const&>(*I));
634+
}
635+
}
636+
637+
void
638+
JavadocFinalizer::
639+
warnNoParamDocs(FunctionInfo const& I) const
640+
{
602641
// Check for function parameters that are not documented in javadoc
642+
auto javadocParamNames = getJavadocParamNames(*I.javadoc);
603643
auto paramNames =
604-
I.Params |
605-
std::views::transform(&Param::Name) |
644+
std::views::transform(I.Params, &Param::Name) |
606645
std::views::filter([](std::string_view const& name) { return !name.empty(); });
607646
for (auto const& paramName: paramNames)
608647
{
@@ -619,21 +658,30 @@ warnParamErrors(FunctionInfo const& I) const
619658
}
620659
}
621660

622-
// Check for documented parameters that don't exist in the function
623-
for (std::string_view javadocParamName: javadocParamNames)
661+
// Check for undocumented return type
662+
if (I.javadoc->returns.empty() && I.ReturnType)
624663
{
625-
if (std::ranges::find(paramNames, javadocParamName) == paramNames.end())
664+
auto isVoid = [](TypeInfo const& returnType) -> bool
665+
{
666+
if (returnType.isNamed())
667+
{
668+
auto const& namedReturnType = dynamic_cast<NamedTypeInfo const&>(returnType);
669+
return namedReturnType.Name->Name == "void";
670+
}
671+
return false;
672+
};
673+
if (!isVoid(*I.ReturnType))
626674
{
627675
auto primaryLoc = getPrimaryLocation(I);
628676
warn(
629677
"{}:{}\n"
630-
"{}: Documented parameter '{}' does not exist",
678+
"{}: Missing documentation for return type",
631679
primaryLoc->FullPath,
632680
primaryLoc->LineNumber,
633-
corpus_.Corpus::qualifiedName(I),
634-
javadocParamName);
681+
corpus_.Corpus::qualifiedName(I));
635682
}
636683
}
637684
}
638685

686+
639687
} // clang::mrdocs

src/lib/Metadata/Finalizers/JavadocFinalizer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ class JavadocFinalizer
181181

182182
void
183183
warnParamErrors(FunctionInfo const& I) const;
184+
185+
void
186+
warnNoParamDocs() const;
187+
188+
void
189+
warnNoParamDocs(FunctionInfo const& I) const;
184190
};
185191

186192
} // clang::mrdocs
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
inherit-base-members: copy-dependencies
22
exclude-symbols:
3-
- excluded_base
3+
- excluded_base
4+
warn-no-paramdoc: false
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
inherit-base-members: copy-all
22
exclude-symbols:
3-
- excluded_base
3+
- excluded_base
4+
warn-no-paramdoc: false
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
inherit-base-members: never
22
exclude-symbols:
3-
- excluded_base
3+
- excluded_base
4+
warn-no-paramdoc: false
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
inherit-base-members: reference
22
exclude-symbols:
3-
- excluded_base
3+
- excluded_base
4+
warn-no-paramdoc: false

test-files/golden-tests/filters/symbol-name/extraction-mode.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ implementation-defined:
2929
- 'excluded_ns::implementation_defined'
3030
- 'implementation_defined_ns'
3131
- 'implementation_defined'
32+
warn-no-paramdoc: false

test-files/golden-tests/javadoc/ref/operator-param.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ bool
9393
operator()(char ch) const noexcept;
9494
----
9595

96+
=== Return Value
97+
98+
99+
True if ch is in the set, otherwise false&period;
100+
96101
=== Parameters
97102

98103

@@ -129,6 +134,11 @@ This function returns true if the character is in the set, otherwise
129134

130135

131136

137+
=== Return Value
138+
139+
140+
True if ch is in the set, otherwise false&period;
141+
132142
=== Parameters
133143

134144

0 commit comments

Comments
 (0)