Skip to content

Add warning/error handling for --include-external #1293

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

Closed
Closed
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
34 changes: 27 additions & 7 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,36 @@ class DartDoc {
}

// Use the includeExternals.
for (Source source in context.librarySources) {
bool matchesLibrary(String includeExternal, Source source) {
LibraryElement library = context.computeLibraryElement(source);
String libraryName = Library.getLibraryName(library);
var fullPath = source.fullName;
if (includeExternals.any((string) => fullPath.endsWith(string))) {
if (libraries.map(Library.getLibraryName).contains(libraryName)) {
continue;
}
libraries.add(library);
return source.fullName.endsWith(includeExternal);
}

for (String includeExternal in includeExternals) {
var quotedArgString = "'--include-external $includeExternal'";
List<Source> matchedSources = context.librarySources
.where((library) => matchesLibrary(includeExternal, library));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .toList() here – make sure we don't re-iterate the iterable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would it mean to re-iterate the iterable? Is this a general pattern we should have the analyzer warn about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I should write-up a little dartpad thing to show this.

if (matchedSources.isEmpty) {
print(" warning: $quotedArgString -- " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: + not needed here. adjacent String literals auto-concat. Is nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

"no library found matching $includeExternal.");
continue;
}
if (matchedSources.length > 1) {
var indentedMatchedPaths =
' ' + matchedSources.map((source) => source.fullName).join('\n ');
throw new DartDocFailure("$quotedArgString -- " +
"multiple libraries found matching $includeExternal:\n" +
"$indentedMatchedPaths");
}
Source source = matchedSources.first;
LibraryElement library = context.computeLibraryElement(source);
String libraryName = Library.getLibraryName(library);
if (libraries.map(Library.getLibraryName).contains(libraryName)) {
print(" info: $quotedArgString ignored, $libraryName already seen.");
continue;
}
libraries.add(library);
}

List<AnalysisErrorInfo> errorInfos = [];
Expand Down