Skip to content

Fix issue where excluded packages can sometimes default to remote linking #2387

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 6 commits into from
Oct 13, 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
4 changes: 2 additions & 2 deletions lib/src/model/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ class Class extends Container
var result = <Class>{};
var seen = <Class>{};

// Recursively adds [implementor] if public, or the impelentors of
// Recursively adds [implementor] if public, or the implementors of
// [implementor] if not.
void addToResult(Class implementor) {
if (seen.contains(implementor)) return;
seen.add(implementor);
if (implementor.isPublic) {
if (implementor.isPublicAndPackageDocumented) {
result.add(implementor);
} else {
model_utils
Expand Down
3 changes: 1 addition & 2 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,7 @@ abstract class ModelElement extends Canonicalization
@override
Package get package => library?.package;

bool get isPublicAndPackageDocumented =>
isPublic && library.packageGraph.packageDocumentedFor(this);
bool get isPublicAndPackageDocumented => isPublic && package.isDocumented;

List<Parameter> _allParameters;

Expand Down
5 changes: 4 additions & 1 deletion lib/src/model/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ class Package extends LibraryContainer
_documentedWhere = DocumentLocation.local;
}
} else {
if (config.linkToRemote && config.linkToUrl.isNotEmpty && isPublic) {
if (config.linkToRemote &&
config.linkToUrl.isNotEmpty &&
isPublic &&
!packageGraph.config.isPackageExcluded(name)) {
_documentedWhere = DocumentLocation.remote;
} else {
_documentedWhere = DocumentLocation.missing;
Expand Down
14 changes: 0 additions & 14 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,6 @@ class PackageGraph {
bool allLibrariesAdded = false;
bool _localDocumentationBuilt = false;

Set<String> _allRootDirs;

/// Returns true if there's at least one library documented in the package
/// that has the same package path as the library for the given element.
///
/// Usable as a cross-check for dartdoc's canonicalization to generate
/// warnings for ModelElement.isPublicAndPackageDocumented.
bool packageDocumentedFor(ModelElement element) {
_allRootDirs ??= {
...(publicLibraries.map((l) => l.packageMeta?.resolvedDir))
};
return _allRootDirs.contains(element.library.packageMeta?.resolvedDir);
}

PackageWarningCounter get packageWarningCounter => _packageWarningCounter;

final Set<Tuple3<Element, PackageWarning, String>> _warnAlreadySeen = {};
Expand Down
5 changes: 4 additions & 1 deletion test/end2end/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ void main() {
});

test('basic interlinking test', () async {
var dartdoc = await buildDartdoc([], _testPackageDir, tempDir);
var dartdoc = await buildDartdoc(
['--exclude-packages=args'], _testPackageDir, tempDir);
var results = await dartdoc.generateDocs();
var p = results.packageGraph;
var meta = p.publicPackages.firstWhere((p) => p.name == 'meta');
var args = p.publicPackages.firstWhere((p) => p.name == 'args');
var useSomethingInAnotherPackage = p.publicLibraries
.firstWhere((l) => l.name == 'fake')
.properties
Expand All @@ -219,6 +221,7 @@ void main() {
.properties
.firstWhere((p) => p.name == 'useSomethingInTheSdk');
expect(meta.documentedWhere, equals(DocumentLocation.remote));
expect(args.documentedWhere, equals(DocumentLocation.missing));
expect(
useSomethingInAnotherPackage.modelType.linkedName,
matches(
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ void main() {
});

test('correctly finds all the classes', () {
expect(classes, hasLength(37));
expect(classes, hasLength(38));
});

test('abstract', () {
Expand Down
1 change: 1 addition & 0 deletions testing/test_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:math';
import 'src/mylib.dart' show Helper;
import 'package:test_package_imported/main.dart';

export 'package:args/args.dart' show ArgParser;
export 'dart:core' show deprecated, Deprecated;
import 'package:meta/meta.dart' show protected, factory;

Expand Down
2 changes: 0 additions & 2 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,6 @@ Future<WarningsCollection> _buildDartdocFlutterPluginDocs() async {
[
'--enable-asserts',
path.join(Directory.current.path, 'bin', 'dartdoc.dart'),
'--exclude-packages',
'Dart', // TODO(jcollins-g): dart-lang/dartdoc#1431
'--json',
'--link-to-remote',
'--output',
Expand Down