From 4631023df66d9a75e0fb7b3ba58d64e1882b0fa0 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Mon, 17 Jun 2024 11:45:24 -0700 Subject: [PATCH 1/2] Declare local variables for the 'href' field, to promote and avoid printing 'null' --- lib/src/markdown_processor.dart | 8 +++----- lib/src/model/category.dart | 5 +++++ lib/src/model/model_element.dart | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/markdown_processor.dart b/lib/src/markdown_processor.dart index e6405aafeb..64e68199b4 100644 --- a/lib/src/markdown_processor.dart +++ b/lib/src/markdown_processor.dart @@ -314,15 +314,13 @@ class MarkdownDocument extends md.Document { var textContent = _htmlEscape.convert(referenceText); var linkedElement = result.commentReferable; if (linkedElement != null) { - if (linkedElement.href != null) { + var href = linkedElement.href; + if (href != null) { var anchor = md.Element.text('a', textContent); if (linkedElement is ModelElement && linkedElement.isDeprecated) { anchor.attributes['class'] = 'deprecated'; } - var href = linkedElement.href; - if (href != null) { - anchor.attributes['href'] = href; - } + anchor.attributes['href'] = href; return anchor; } else { // Otherwise this would be `linkedElement.linkedName`, but link bodies diff --git a/lib/src/model/category.dart b/lib/src/model/category.dart index e6383df1db..dc9e49f937 100644 --- a/lib/src/model/category.dart +++ b/lib/src/model/category.dart @@ -143,6 +143,11 @@ class Category String get linkedName { final unbrokenName = name.replaceAll(' ', ' '); if (isDocumented) { + final href = this.href; + if (href == null) { + throw StateError("Requesting the 'linkedName' of a non-canonical " + "category: '$name'"); + } return '$unbrokenName'; } else { return unbrokenName; diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 58d557ca7c..e62328937c 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -687,6 +687,7 @@ abstract class ModelElement element.kind == ElementKind.NEVER || this is ModelFunction); + final href = this.href; if (href == null) { if (isPublicAndPackageDocumented) { warn(PackageWarning.noCanonicalFound); From bb7eb05dd20813852421d6e91efb194de1f3b21d Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 18 Jun 2024 11:02:05 -0700 Subject: [PATCH 2/2] patterns --- lib/src/markdown_processor.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/markdown_processor.dart b/lib/src/markdown_processor.dart index 64e68199b4..640ce308e9 100644 --- a/lib/src/markdown_processor.dart +++ b/lib/src/markdown_processor.dart @@ -314,8 +314,7 @@ class MarkdownDocument extends md.Document { var textContent = _htmlEscape.convert(referenceText); var linkedElement = result.commentReferable; if (linkedElement != null) { - var href = linkedElement.href; - if (href != null) { + if (linkedElement.href case var href?) { var anchor = md.Element.text('a', textContent); if (linkedElement is ModelElement && linkedElement.isDeprecated) { anchor.attributes['class'] = 'deprecated';