Skip to content

Commit 4631023

Browse files
committed
Declare local variables for the 'href' field, to promote and avoid printing 'null'
1 parent 14d33d3 commit 4631023

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/src/markdown_processor.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,13 @@ 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+
var href = linkedElement.href;
318+
if (href != null) {
318319
var anchor = md.Element.text('a', textContent);
319320
if (linkedElement is ModelElement && linkedElement.isDeprecated) {
320321
anchor.attributes['class'] = 'deprecated';
321322
}
322-
var href = linkedElement.href;
323-
if (href != null) {
324-
anchor.attributes['href'] = href;
325-
}
323+
anchor.attributes['href'] = href;
326324
return anchor;
327325
} else {
328326
// 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)