Skip to content

Warn when the defining library cannot be found #2319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,13 @@ abstract class ModelElement extends Canonicalization
documentationFrom.map((e) => e.documentationLocal).join('<p>'));
}

Library get definingLibrary =>
packageGraph.findButDoNotCreateLibraryFor(element);
Library get definingLibrary {
var library = packageGraph.findButDoNotCreateLibraryFor(element);
if (library == null) {
warn(PackageWarning.noDefiningLibraryFound);
}
return library;
}

Library _canonicalLibrary;

Expand Down Expand Up @@ -700,6 +705,9 @@ abstract class ModelElement extends Canonicalization
}

Library _searchForCanonicalLibrary() {
if (definingLibrary == null) {
return null;
}
var thisAndExported = definingLibrary.exportedInLibraries;

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

@override
Package get package => library.package;
Package get package => library?.package;

bool get isPublicAndPackageDocumented =>
isPublic && library.packageGraph.packageDocumentedFor(this);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ class PackageGraph {
warningMessage =
'ambiguous reexport of ${warnableName}, canonicalization candidates: ${message}';
break;
case PackageWarning.noDefiningLibraryFound:
warningMessage =
'could not find the defining library for ${warnableName}; the '
'library may be imported or exported with a non-standard URI';
break;
case PackageWarning.noLibraryLevelDocs:
warningMessage =
'${warnable.fullyQualifiedName} has no library level documentation comments';
Expand Down
18 changes: 13 additions & 5 deletions lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,20 @@ final Map<PackageWarning, PackageWarningDefinition> packageWarningDefinitions =
PackageWarning.ignoredCanonicalFor: PackageWarningDefinition(
PackageWarning.ignoredCanonicalFor,
'ignored-canonical-for',
'A @canonicalFor tag refers to a library which this symbol can not be canonical for'),
'A @canonicalFor tag refers to a library which this symbol can not be '
'canonical for'),
PackageWarning.noCanonicalFound: PackageWarningDefinition(
PackageWarning.noCanonicalFound,
'no-canonical-found',
'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'),
'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'),
PackageWarning.noDefiningLibraryFound: PackageWarningDefinition(
PackageWarning.noDefiningLibraryFound,
'no-defining-library-found',
'The defining library for an element could not be found; the library may '
'be imported or exported with a non-standard URI',
defaultWarningMode: PackageWarningMode.error),
PackageWarning.notImplemented: PackageWarningDefinition(
PackageWarning.notImplemented,
'not-implemented',
Expand Down Expand Up @@ -245,6 +254,7 @@ enum PackageWarning {
ambiguousReexport,
ignoredCanonicalFor,
noCanonicalFound,
noDefiningLibraryFound,
notImplemented,
noLibraryLevelDocs,
packageOrderGivesMissingPackageName,
Expand Down Expand Up @@ -441,9 +451,7 @@ class PackageWarningCounter {
PackageWarningOptionContext config =
element?.config ?? packageGraph.defaultPackage.config;
var warningMode = config.packageWarningOptions.getMode(kind);
if (!config.allowNonLocalWarnings &&
element != null &&
!element.package.isLocal) {
if (!config.allowNonLocalWarnings && !(element?.package?.isLocal ?? true)) {
warningMode = PackageWarningMode.ignore;
}
if (warningMode == PackageWarningMode.warn) {
Expand Down