Skip to content

Commit

Permalink
Remove unresolved-export warning. (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallentu authored Mar 9, 2024
1 parent cdcbf6d commit 353b426
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 106 deletions.
15 changes: 1 addition & 14 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ class PackageGraph with CommentReferable, Nameable {
PackageWarning.invalidParameter ||
PackageWarning.toolError ||
PackageWarning.deprecated ||
PackageWarning.unresolvedExport ||
PackageWarning.missingExampleFile ||
PackageWarning.missingCodeBlockLanguage =>
kind.messageFor([message])
Expand Down Expand Up @@ -513,19 +512,7 @@ class PackageGraph with CommentReferable, Nameable {
return;
}
_reexportsTagged.add(key);
if (libraryElement == null) {
lastExportedElement!;
final lastExportedElementUri = lastExportedElement.uri;
final uri = lastExportedElementUri is DirectiveUriWithRelativeUriString
? lastExportedElementUri.relativeUriString
: null;
warnOnElement(
findButDoNotCreateLibraryFor(lastExportedElement.enclosingElement!),
PackageWarning.unresolvedExport,
message: '"$uri"',
referredFrom: <Locatable>[topLevelLibrary]);
return;
}
if (libraryElement == null) return;
_libraryExports.putIfAbsent(libraryElement, () => {}).add(topLevelLibrary);
for (var exportedElement in libraryElement.libraryExports) {
_tagReexportsFor(
Expand Down
6 changes: 0 additions & 6 deletions lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,6 @@ enum PackageWarning implements Comparable<PackageWarning> {
'deprecated dartdoc usage: {0}',
shortHelp: 'A dartdoc directive has a deprecated format.',
),
unresolvedExport(
'unresolved-export',
'unresolved export uri: {0}',
shortHelp: 'An export refers to a URI that cannot be resolved.',
defaultWarningMode: PackageWarningMode.error,
),
missingExampleFile(
'missing-example-file',
'example file not found: {0}',
Expand Down
87 changes: 1 addition & 86 deletions test/warnings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ library dartdoc.warnings_test;

import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/generator/generator.dart';
import 'package:dartdoc/src/io_utils.dart';
import 'package:dartdoc/src/model/package_builder.dart';
import 'package:dartdoc/src/package_config_provider.dart';
import 'package:dartdoc/src/package_meta.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -59,7 +55,6 @@ void main() async {
dartdoc:
warnings:
- type-as-html
- unresolved-export
errors:
- unresolved-doc-reference
ignore:
Expand Down Expand Up @@ -89,7 +84,6 @@ dartdoc:
dartdoc:
warnings:
- type-as-html
- unresolved-export
errors:
- unresolved-doc-reference
ignore:
Expand All @@ -102,8 +96,6 @@ dartdoc:

expect(options.warningModes[PackageWarning.typeAsHtml],
equals(PackageWarningMode.warn));
expect(options.warningModes[PackageWarning.unresolvedExport],
equals(PackageWarningMode.warn));
expect(options.warningModes[PackageWarning.unresolvedDocReference],
equals(PackageWarningMode.error));
expect(options.warningModes[PackageWarning.ambiguousReexport],
Expand All @@ -115,7 +107,6 @@ dartdoc:
dartdoc:
warnings:
- type-as-html
- unresolved-export
errors:
- unresolved-doc-reference
ignore:
Expand All @@ -127,14 +118,12 @@ dartdoc:
'--errors',
'type-as-html',
'--ignore',
'unresolved-export',
'',
]);
PackageWarningOptions options = optionSet['packageWarningOptions']
.valueAt(resourceProvider.getFolder(d.dir('test_package').io.path));
expect(options.warningModes[PackageWarning.typeAsHtml],
equals(PackageWarningMode.error));
expect(options.warningModes[PackageWarning.unresolvedExport],
equals(PackageWarningMode.ignore));
// `unresolved-doc-reference` is not mentioned in command line, so it
// reverts to default.
expect(options.warningModes[PackageWarning.unresolvedDocReference],
Expand All @@ -149,7 +138,6 @@ dartdoc:
dartdoc:
warnings:
- type-as-html
- unresolved-export
errors:
- unresolved-doc-reference
ignore:
Expand All @@ -168,82 +156,9 @@ dartdoc:

expect(options.warningModes[PackageWarning.typeAsHtml],
equals(PackageWarningMode.ignore));
expect(options.warningModes[PackageWarning.unresolvedExport],
equals(PackageWarningMode.error));
expect(options.warningModes[PackageWarning.unresolvedDocReference],
equals(PackageWarningMode.warn));
expect(options.warningModes[PackageWarning.ambiguousReexport],
equals(PackageWarningMode.warn));
});

test('warns of a broken re-export chain', () async {
await d.createPackage(
'test_package',
pubspec: '''
name: test_package
version: 0.0.1
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
test_package_export_error:
path: ../test_package_export_error
''',
libFiles: [
d.file('lib.dart', '''
export 'package:test_package_export_error/library2.dart';
/// This is an important class.
class BugFreeClass {}
'''),
],
);
await d.createPackage(
'test_package_export_error',
pubspec: '''
name: test_package_export_error
version: 0.0.1
environment:
sdk: '>=2.12.0 <3.0.0'
''',
libFiles: [
d.file('library1.dart', '''
/// An export of a non-existent library.
export 'package:not_referenced_in_pubspec/library3.dart' show Lib3Class;
'''),
d.file('library2.dart', '''
export 'package:test_package_export_error/library1.dart';
class Lib2Class {}
'''),
],
);

var tempDir = resourceProvider.createSystemTemp('dartdoc.test.');

var optionSet = DartdocOptionRoot.fromOptionGenerators(
'dartdoc',
[
createDartdocOptions,
createGeneratorOptions,
],
pubPackageMetaProvider);
optionSet.parseArguments(
['--input', d.dir('test_package').io.path, '--output', tempDir.path]);
var context = DartdocGeneratorOptionContext.fromDefaultContextLocation(
optionSet, pubPackageMetaProvider.resourceProvider);

var packageGraph = await PubPackageBuilder(
context, pubPackageMetaProvider, PhysicalPackageConfigProvider(),
skipUnreachableSdkLibraries: true)
.buildPackageGraph();

var unresolvedExportWarnings = packageGraph
.packageWarningCounter.countedWarnings.values
.map((e) => e[PackageWarning.unresolvedExport] ?? {})
.expand((element) => element);

expect(unresolvedExportWarnings, hasLength(1));
expect(unresolvedExportWarnings.first,
equals('"package:not_referenced_in_pubspec/library3.dart"'));
});
}

0 comments on commit 353b426

Please sign in to comment.