Skip to content

Commit ceac197

Browse files
authored
Do not throw on "empty" package; emit warning instead (#2360)
* Only emit a log message instead of throwing. * Add a full warning and test * Dartfmt * Fix comment * Fix empty package check in packages test
1 parent a597dd0 commit ceac197

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

lib/dartdoc.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ class Dartdoc {
222222

223223
var dartdocResults = await generateDocsBase();
224224
if (dartdocResults.packageGraph.localPublicLibraries.isEmpty) {
225-
throw DartdocFailure(
226-
'dartdoc could not find any libraries to document');
225+
logWarning('dartdoc could not find any libraries to document');
227226
}
228227

229228
final errorCount =

lib/src/model/package.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ class Package extends LibraryContainer
186186
if (isLocal) {
187187
if (isPublic) {
188188
_documentedWhere = DocumentLocation.local;
189-
} else {
190-
// Possible if excludes result in a "documented" package not having
191-
// any actual documentation.
192-
_documentedWhere = DocumentLocation.missing;
193189
}
194190
} else {
195191
if (config.linkToRemote && config.linkToUrl.isNotEmpty && isPublic) {

lib/src/model/package_graph.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class PackageGraph {
7575

7676
// Scan all model elements to insure that interceptor and other special
7777
// objects are found.
78+
// Emit warnings for any local package that has no libraries.
7879
// After the allModelElements traversal to be sure that all packages
7980
// are picked up.
8081
for (var package in documentedPackages) {
@@ -83,6 +84,9 @@ class PackageGraph {
8384
_addToImplementors(library.allClasses);
8485
_extensions.addAll(library.extensions);
8586
}
87+
if (package.isLocal && !package.hasPublicLibraries) {
88+
package.warn(PackageWarning.noDocumentableLibrariesInPackage);
89+
}
8690
}
8791
for (var l in _implementors.values) {
8892
l.sort();
@@ -362,6 +366,10 @@ class PackageGraph {
362366
warningMessage =
363367
'${warnable.fullyQualifiedName} has no library level documentation comments';
364368
break;
369+
case PackageWarning.noDocumentableLibrariesInPackage:
370+
warningMessage =
371+
'${warnable.fullyQualifiedName} has no documentable libraries';
372+
break;
365373
case PackageWarning.ambiguousDocReference:
366374
warningMessage = 'ambiguous doc reference $message';
367375
break;

lib/src/warnings.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ final Map<PackageWarning, PackageWarningDefinition> packageWarningDefinitions =
159159
PackageWarning.notImplemented,
160160
'not-implemented',
161161
'The code makes use of a feature that is not yet implemented in dartdoc'),
162+
PackageWarning.noDocumentableLibrariesInPackage: PackageWarningDefinition(
163+
PackageWarning.noDocumentableLibrariesInPackage,
164+
'no-documentable-libraries',
165+
'The package is to be documented but has no Dart libraries to document',
166+
longHelp: [
167+
'Dartdoc could not find any public libraries to document in @@name@@, ',
168+
'but documentation was requested. This might be expected for an ',
169+
'asset only package, in which case, disable this warning in your ',
170+
'dartdoc_options.yaml file.',
171+
],
172+
),
162173
PackageWarning.noLibraryLevelDocs: PackageWarningDefinition(
163174
PackageWarning.noLibraryLevelDocs,
164175
'no-library-level-docs',
@@ -266,6 +277,7 @@ enum PackageWarning {
266277
noCanonicalFound,
267278
noDefiningLibraryFound,
268279
notImplemented,
280+
noDocumentableLibrariesInPackage,
269281
noLibraryLevelDocs,
270282
packageOrderGivesMissingPackageName,
271283
reexportedPrivateApiAcrossPackages,

test/end2end/dartdoc_integration_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ String get _testPackagePath =>
2121
path.fromUri(_currentFileUri.resolve('../../testing/test_package'));
2222
String get _testPackageFlutterPluginPath => path.fromUri(_currentFileUri
2323
.resolve('../../testing/flutter_packages/test_package_flutter_plugin'));
24+
String get _testPackageMinimumPath =>
25+
path.fromUri(_currentFileUri.resolve('../../testing/test_package_minimum'));
2426

2527
void main() {
2628
group('Invoking command-line dartdoc', () {
@@ -45,6 +47,20 @@ void main() {
4547
await Future.wait(CoverageSubprocessLauncher.coverageResults);
4648
});
4749

50+
test('running on an empty package does not crash and generates a warning',
51+
() async {
52+
var outputDir =
53+
await Directory.systemTemp.createTemp('dartdoc.testEmpty.');
54+
var outputLines = <String>[];
55+
await subprocessLauncher.runStreamed(Platform.resolvedExecutable,
56+
[dartdocPath, '--output', outputDir.path],
57+
perLine: outputLines.add, workingDirectory: _testPackageMinimumPath);
58+
expect(
59+
outputLines,
60+
contains(matches(
61+
'package:test_package_minimum has no documentable libraries')));
62+
}, timeout: Timeout.factor(2));
63+
4864
test('running --no-generate-docs is quiet and does not generate docs',
4965
() async {
5066
var outputDir =
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: test_package_minimum
2+
homepage: http://github.com/dart-lang
3+
description: The only package with no bugs.
4+
version: 0.0.3

tool/travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ elif [ "$DARTDOC_BOT" = "packages" ]; then
3636
fi
3737
PACKAGE_NAME=access PACKAGE_VERSION=">=1.0.1+2" pub run grinder build-pub-package
3838
# Negative test for flutter_plugin_tools, make sure right error message is displayed.
39-
PACKAGE_NAME=flutter_plugin_tools PACKAGE_VERSION=">=0.0.14+1" pub run grinder build-pub-package 2>&1 | grep "dartdoc failed: dartdoc could not find any libraries to document.$"
39+
PACKAGE_NAME=flutter_plugin_tools PACKAGE_VERSION=">=0.0.14+1" pub run grinder build-pub-package 2>&1 | grep "warning: package:flutter_plugin_tools has no documentable libraries"
4040
PACKAGE_NAME=shelf_exception_handler PACKAGE_VERSION=">=0.2.0" pub run grinder build-pub-package
4141
elif [ "$DARTDOC_BOT" = "sdk-analyzer" ]; then
4242
echo "Running all tests against the SDK analyzer"

0 commit comments

Comments
 (0)