Skip to content

Commit 6412c80

Browse files
committed
warn-broken-ref option
#feat
1 parent 7669da0 commit 6412c80

File tree

6 files changed

+55
-28
lines changed

6 files changed

+55
-28
lines changed

docs/mrdocs.schema.json

+10
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,16 @@
450450
"title": "Verbose output",
451451
"type": "boolean"
452452
},
453+
"warn-broken-ref": {
454+
"default": true,
455+
"description": "When set to `true`, MrDocs outputs a warning message if a reference in the documentation is broken.",
456+
"enum": [
457+
true,
458+
false
459+
],
460+
"title": "Warn if a documentation reference is broken",
461+
"type": "boolean"
462+
},
453463
"warn-if-doc-error": {
454464
"default": true,
455465
"description": "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.",

src/lib/Lib/ConfigOptions.json

+7
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@
506506
"details": "When set to `true`, MrDocs outputs a warning message if an enum value is not documented.",
507507
"type": "bool",
508508
"default": true
509+
},
510+
{
511+
"name": "warn-broken-ref",
512+
"brief": "Warn if a documentation reference is broken",
513+
"details": "When set to `true`, MrDocs outputs a warning message if a reference in the documentation is broken.",
514+
"type": "bool",
515+
"default": true
509516
}
510517
]
511518
},

src/lib/Metadata/Finalizers/JavadocFinalizer.cpp

+35-25
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ finalize(doc::Reference& ref)
118118
ref.id = res->id;
119119
}
120120
if (res == nullptr &&
121+
corpus_.config->warnings &&
122+
corpus_.config->warnBrokenRef &&
121123
// Only warn once per reference
122124
!warned_.contains({ref.string, current_context_->Name}) &&
123125
// Ignore std:: references
@@ -128,7 +130,7 @@ finalize(doc::Reference& ref)
128130
MRDOCS_ASSERT(current_context_);
129131
if (auto primaryLoc = getPrimaryLocation(*current_context_))
130132
{
131-
warn(
133+
this->warn(
132134
"{}:{}\n{}: Failed to resolve reference to '{}'",
133135
primaryLoc->FullPath,
134136
primaryLoc->LineNumber,
@@ -281,10 +283,13 @@ copyBriefAndDetails(Javadoc& javadoc)
281283
Info const* res = corpus_.lookup(current_context_->id, copied->string);
282284
if (!res)
283285
{
284-
MRDOCS_ASSERT(current_context_);
285-
if (auto primaryLoc = getPrimaryLocation(*current_context_))
286+
if (corpus_.config->warnings &&
287+
corpus_.config->warnBrokenRef &&
288+
!warned_.contains({copied->string, current_context_->Name}))
286289
{
287-
warn(
290+
MRDOCS_ASSERT(current_context_);
291+
auto primaryLoc = getPrimaryLocation(*current_context_);
292+
this->warn(
288293
"{}:{}\n"
289294
"{}: Failed to copy documentation from '{}'\n"
290295
" Note: Symbol '{}' not found.",
@@ -304,21 +309,26 @@ copyBriefAndDetails(Javadoc& javadoc)
304309
}
305310
if (!res->javadoc)
306311
{
307-
auto ctxPrimaryLoc = getPrimaryLocation(*current_context_);
308-
auto resPrimaryLoc = getPrimaryLocation(*res);
309-
warn(
310-
"{}:{}\n"
311-
"{}: Failed to copy documentation from '{}'.\n"
312-
"No documentation available.\n"
313-
" {}:{}\n"
314-
" Note: No documentation available for '{}'.",
315-
ctxPrimaryLoc->FullPath,
316-
ctxPrimaryLoc->LineNumber,
317-
corpus_.Corpus::qualifiedName(*current_context_),
318-
copied->string,
319-
resPrimaryLoc->FullPath,
320-
resPrimaryLoc->LineNumber,
321-
corpus_.Corpus::qualifiedName(*res));
312+
if (corpus_.config->warnings &&
313+
corpus_.config->warnBrokenRef &&
314+
!warned_.contains({copied->string, current_context_->Name}))
315+
{
316+
auto ctxPrimaryLoc = getPrimaryLocation(*current_context_);
317+
auto resPrimaryLoc = getPrimaryLocation(*res);
318+
this->warn(
319+
"{}:{}\n"
320+
"{}: Failed to copy documentation from '{}'.\n"
321+
"No documentation available.\n"
322+
" {}:{}\n"
323+
" Note: No documentation available for '{}'.",
324+
ctxPrimaryLoc->FullPath,
325+
ctxPrimaryLoc->LineNumber,
326+
corpus_.Corpus::qualifiedName(*current_context_),
327+
copied->string,
328+
resPrimaryLoc->FullPath,
329+
resPrimaryLoc->LineNumber,
330+
corpus_.Corpus::qualifiedName(*res));
331+
}
322332
continue;
323333
}
324334

@@ -531,7 +541,7 @@ warnUndocumented() const
531541
{
532542
MRDOCS_CHECK_OR(!I->javadoc || I->Extraction == ExtractionMode::Regular);
533543
}
534-
warn("{}: Symbol is undocumented", name);
544+
this->warn("{}: Symbol is undocumented", name);
535545
}
536546
corpus_.undocumented_.clear();
537547
}
@@ -590,7 +600,7 @@ warnParamErrors(FunctionInfo const& I) const
590600
std::string_view duplicateParamName: uniqueDuplicateParamNames)
591601
{
592602
auto primaryLoc = getPrimaryLocation(I);
593-
warn(
603+
this->warn(
594604
"{}:{}\n"
595605
"{}: Duplicate parameter documentation for '{}'",
596606
primaryLoc->FullPath,
@@ -609,7 +619,7 @@ warnParamErrors(FunctionInfo const& I) const
609619
if (std::ranges::find(paramNames, javadocParamName) == paramNames.end())
610620
{
611621
auto primaryLoc = getPrimaryLocation(I);
612-
warn(
622+
this->warn(
613623
"{}:{}\n"
614624
"{}: Documented parameter '{}' does not exist",
615625
primaryLoc->FullPath,
@@ -649,7 +659,7 @@ warnNoParamDocs(FunctionInfo const& I) const
649659
if (std::ranges::find(javadocParamNames, paramName) == javadocParamNames.end())
650660
{
651661
auto primaryLoc = getPrimaryLocation(I);
652-
warn(
662+
this->warn(
653663
"{}:{}\n"
654664
"{}: Missing documentation for parameter '{}'",
655665
primaryLoc->FullPath,
@@ -674,7 +684,7 @@ warnNoParamDocs(FunctionInfo const& I) const
674684
if (!isVoid(*I.ReturnType))
675685
{
676686
auto primaryLoc = getPrimaryLocation(I);
677-
warn(
687+
this->warn(
678688
"{}:{}\n"
679689
"{}: Missing documentation for return type",
680690
primaryLoc->FullPath,
@@ -695,7 +705,7 @@ warnUndocEnumValues() const
695705
MRDOCS_CHECK_OR_CONTINUE(I->Extraction == ExtractionMode::Regular);
696706
MRDOCS_CHECK_OR_CONTINUE(!I->javadoc);
697707
auto primaryLoc = getPrimaryLocation(*I);
698-
warn(
708+
this->warn(
699709
"{}:{}\n"
700710
"{}: Missing documentation for enum value",
701711
primaryLoc->FullPath,
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
auto-brief: true
2-
warnings: false
2+
warn-broken-ref: false
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
auto-brief: false
2-
warnings: false
2+
warn-broken-ref: false
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
warnings: false
1+
warn-broken-ref: false

0 commit comments

Comments
 (0)