Skip to content

Commit 6330a13

Browse files
authored
Declare local variables for the 'href' field, to promote and avoid printing 'null' (#3788)
1 parent 822ca00 commit 6330a13

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib/src/markdown_processor.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,12 @@ class MarkdownDocument extends md.Document {
314314
var textContent = _htmlEscape.convert(referenceText);
315315
var linkedElement = result.commentReferable;
316316
if (linkedElement != null) {
317-
if (linkedElement.href != null) {
317+
if (linkedElement.href case var href?) {
318318
var anchor = md.Element.text('a', textContent);
319319
if (linkedElement is ModelElement && linkedElement.isDeprecated) {
320320
anchor.attributes['class'] = 'deprecated';
321321
}
322-
var href = linkedElement.href;
323-
if (href != null) {
324-
anchor.attributes['href'] = href;
325-
}
322+
anchor.attributes['href'] = href;
326323
return anchor;
327324
} else {
328325
// Otherwise this would be `linkedElement.linkedName`, but link bodies

lib/src/model/category.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class Category
143143
String get linkedName {
144144
final unbrokenName = name.replaceAll(' ', ' ');
145145
if (isDocumented) {
146+
final href = this.href;
147+
if (href == null) {
148+
throw StateError("Requesting the 'linkedName' of a non-canonical "
149+
"category: '$name'");
150+
}
146151
return '<a href="$href">$unbrokenName</a>';
147152
} else {
148153
return unbrokenName;

lib/src/model/model_element.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ abstract class ModelElement
687687
element.kind == ElementKind.NEVER ||
688688
this is ModelFunction);
689689

690+
final href = this.href;
690691
if (href == null) {
691692
if (isPublicAndPackageDocumented) {
692693
warn(PackageWarning.noCanonicalFound);

0 commit comments

Comments
 (0)