Skip to content

Commit

Permalink
Declare local variables for the 'href' field, to promote and avoid pr…
Browse files Browse the repository at this point in the history
…inting 'null'
  • Loading branch information
srawlins committed Jun 17, 2024
1 parent 14d33d3 commit a3d519b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 anchor = md.Element.text('a', textContent);
var href = linkedElement.href;
if (href != null) {
var anchor = md.Element.text('a', textContent)
..attributes['href'] = href;
if (linkedElement is ModelElement && linkedElement.isDeprecated) {
anchor.attributes['class'] = 'deprecated';
}
var href = linkedElement.href;
if (href != null) {
anchor.attributes['href'] = href;
}
return anchor;
} else {
// Otherwise this would be `linkedElement.linkedName`, but link bodies
Expand Down
5 changes: 5 additions & 0 deletions lib/src/model/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<a href="$href">$unbrokenName</a>';
} else {
return unbrokenName;
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3d519b

Please sign in to comment.