Skip to content

Commit 3fa86a5

Browse files
authored
Warn when the defining library cannot be found (#2319)
1 parent 977f765 commit 3fa86a5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

lib/src/model/model_element.dart

+11-3
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,13 @@ abstract class ModelElement extends Canonicalization
658658
documentationFrom.map((e) => e.documentationLocal).join('<p>'));
659659
}
660660

661-
Library get definingLibrary =>
662-
packageGraph.findButDoNotCreateLibraryFor(element);
661+
Library get definingLibrary {
662+
var library = packageGraph.findButDoNotCreateLibraryFor(element);
663+
if (library == null) {
664+
warn(PackageWarning.noDefiningLibraryFound);
665+
}
666+
return library;
667+
}
663668

664669
Library _canonicalLibrary;
665670

@@ -700,6 +705,9 @@ abstract class ModelElement extends Canonicalization
700705
}
701706

702707
Library _searchForCanonicalLibrary() {
708+
if (definingLibrary == null) {
709+
return null;
710+
}
703711
var thisAndExported = definingLibrary.exportedInLibraries;
704712

705713
if (thisAndExported == null) {
@@ -1023,7 +1031,7 @@ abstract class ModelElement extends Canonicalization
10231031
PackageGraph get packageGraph => _packageGraph;
10241032

10251033
@override
1026-
Package get package => library.package;
1034+
Package get package => library?.package;
10271035

10281036
bool get isPublicAndPackageDocumented =>
10291037
isPublic && library.packageGraph.packageDocumentedFor(this);

lib/src/model/package_graph.dart

+5
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ class PackageGraph {
347347
warningMessage =
348348
'ambiguous reexport of ${warnableName}, canonicalization candidates: ${message}';
349349
break;
350+
case PackageWarning.noDefiningLibraryFound:
351+
warningMessage =
352+
'could not find the defining library for ${warnableName}; the '
353+
'library may be imported or exported with a non-standard URI';
354+
break;
350355
case PackageWarning.noLibraryLevelDocs:
351356
warningMessage =
352357
'${warnable.fullyQualifiedName} has no library level documentation comments';

lib/src/warnings.dart

+13-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,20 @@ final Map<PackageWarning, PackageWarningDefinition> packageWarningDefinitions =
135135
PackageWarning.ignoredCanonicalFor: PackageWarningDefinition(
136136
PackageWarning.ignoredCanonicalFor,
137137
'ignored-canonical-for',
138-
'A @canonicalFor tag refers to a library which this symbol can not be canonical for'),
138+
'A @canonicalFor tag refers to a library which this symbol can not be '
139+
'canonical for'),
139140
PackageWarning.noCanonicalFound: PackageWarningDefinition(
140141
PackageWarning.noCanonicalFound,
141142
'no-canonical-found',
142-
'A symbol is part of the public interface for this package, but no library documented with this package documents it so dartdoc can not link to it'),
143+
'A symbol is part of the public interface for this package, but no '
144+
'library documented with this package documents it so dartdoc can '
145+
'not link to it'),
146+
PackageWarning.noDefiningLibraryFound: PackageWarningDefinition(
147+
PackageWarning.noDefiningLibraryFound,
148+
'no-defining-library-found',
149+
'The defining library for an element could not be found; the library may '
150+
'be imported or exported with a non-standard URI',
151+
defaultWarningMode: PackageWarningMode.error),
143152
PackageWarning.notImplemented: PackageWarningDefinition(
144153
PackageWarning.notImplemented,
145154
'not-implemented',
@@ -245,6 +254,7 @@ enum PackageWarning {
245254
ambiguousReexport,
246255
ignoredCanonicalFor,
247256
noCanonicalFound,
257+
noDefiningLibraryFound,
248258
notImplemented,
249259
noLibraryLevelDocs,
250260
packageOrderGivesMissingPackageName,
@@ -441,9 +451,7 @@ class PackageWarningCounter {
441451
PackageWarningOptionContext config =
442452
element?.config ?? packageGraph.defaultPackage.config;
443453
var warningMode = config.packageWarningOptions.getMode(kind);
444-
if (!config.allowNonLocalWarnings &&
445-
element != null &&
446-
!element.package.isLocal) {
454+
if (!config.allowNonLocalWarnings && !(element?.package?.isLocal ?? true)) {
447455
warningMode = PackageWarningMode.ignore;
448456
}
449457
if (warningMode == PackageWarningMode.warn) {

0 commit comments

Comments
 (0)