diff --git a/bin/dartdoc.dart b/bin/dartdoc.dart index 9b9b87a961..83b3f6180f 100644 --- a/bin/dartdoc.dart +++ b/bin/dartdoc.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.bin; import 'dart:async'; diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index a6b5baf96e..a1ce493077 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -1071,34 +1071,35 @@ abstract class _DartdocArgOption implements DartdocOption { _OptionValueWithContext? _valueAtFromArgsWithContext() { if (!_argResults.wasParsed(argName)) return null; - T retval; // Unlike in _DartdocFileOption, we throw here on inputs being invalid // rather than silently proceeding. This is because the user presumably // typed something wrong on the command line and can therefore fix it. // dartdoc_option.yaml files from other packages may not be fully in the // user's control. if (_isBool || _isListString || _isString) { - retval = _argResults[argName]; + return _OptionValueWithContext( + _argResults[argName], _directoryCurrentPath); } else if (_isInt) { - retval = int.tryParse(_argResults[argName]) as T; - if (retval == null) _throwErrorForTypes(_argResults[argName]); + var value = int.tryParse(_argResults[argName]); + if (value == null) _throwErrorForTypes(_argResults[argName]); + return _OptionValueWithContext(value as T, _directoryCurrentPath); } else if (_isDouble) { - retval = double.tryParse(_argResults[argName]) as T; - if (retval == null) _throwErrorForTypes(_argResults[argName]); + var value = double.tryParse(_argResults[argName]); + if (value == null) _throwErrorForTypes(_argResults[argName]); + return _OptionValueWithContext(value as T, _directoryCurrentPath); } else if (_isMapString) { - retval = {} as T; + var value = {}; for (String pair in _argResults[argName]) { var pairList = pair.split('::'); if (pairList.length != 2) { _throwErrorForTypes(pair); } - assert(pairList.length == 2); - (retval as Map)[pairList.first] = pairList.last; + value[pairList.first] = pairList.last; } + return _OptionValueWithContext(value as T, _directoryCurrentPath); } else { throw UnsupportedError('Type $T is not supported'); } - return _OptionValueWithContext(retval, _directoryCurrentPath); } /// The name of this option as a command line argument. @@ -1130,7 +1131,7 @@ abstract class _DartdocArgOption implements DartdocOption { if (_isBool) { argParser.addFlag(argName, abbr: abbr, - defaultsTo: defaultsTo as bool, + defaultsTo: defaultsTo as bool?, help: help, hide: hide, negatable: negatable); diff --git a/lib/src/model/documentation_comment.dart b/lib/src/model/documentation_comment.dart index e6db74509c..19131354d7 100644 --- a/lib/src/model/documentation_comment.dart +++ b/lib/src/model/documentation_comment.dart @@ -272,15 +272,13 @@ mixin DocumentationComment return await config.tools.runner.run(args, content: basicMatch[2]!, toolErrorCallback: (String message) async { warn(PackageWarning.toolError, message: message); - }, - environment: _toolsEnvironment(invocationIndex: invocationIndex) - as Map); + }, environment: _toolsEnvironment(invocationIndex: invocationIndex)); }); } /// The environment variables to use when running a tool. - Map _toolsEnvironment({required int invocationIndex}) { - return { + Map _toolsEnvironment({required int invocationIndex}) { + var env = { 'SOURCE_LINE': characterLocation?.lineNumber.toString(), 'SOURCE_COLUMN': characterLocation?.columnNumber.toString(), if (sourceFileName != null && package?.packagePath != null) @@ -292,7 +290,9 @@ mixin DocumentationComment 'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary, 'INVOCATION_INDEX': invocationIndex.toString(), 'PACKAGE_INVOCATION_INDEX': (package?.toolInvocationIndex++).toString(), - }..removeWhere((key, value) => value == null); + }; + return (env..removeWhere((key, value) => value == null)) + .cast(); } /// Replace {@example ...} in API comments with the content of named file. diff --git a/lib/src/model/package_builder.dart b/lib/src/model/package_builder.dart index 9855375c92..a005b8e313 100644 --- a/lib/src/model/package_builder.dart +++ b/lib/src/model/package_builder.dart @@ -30,7 +30,6 @@ import 'package:dartdoc/src/package_meta.dart' import 'package:dartdoc/src/quiver.dart' as quiver; import 'package:dartdoc/src/render/renderer_factory.dart'; import 'package:dartdoc/src/special_elements.dart'; -import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as path show Context; /// Everything you need to instantiate a PackageGraph object for documenting. @@ -251,9 +250,8 @@ class PubPackageBuilder implements PackageBuilder { var packageDirs = {basePackageDir}; if (autoIncludeDependencies) { - var info = await (packageConfigProvider - .findPackageConfig(resourceProvider.getFolder(basePackageDir)) - as FutureOr); + var info = (await packageConfigProvider + .findPackageConfig(resourceProvider.getFolder(basePackageDir)))!; for (var package in info.packages) { if (!filterExcludes || !config.exclude.contains(package.name)) { packageDirs.add(_pathContext.dirname( diff --git a/test/dartdoc_options_test.dart b/test/dartdoc_options_test.dart index 3f2a540962..b7ba34b1b7 100644 --- a/test/dartdoc_options_test.dart +++ b/test/dartdoc_options_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.options_test; import 'package:analyzer/file_system/file_system.dart'; @@ -15,16 +13,16 @@ import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; class ConvertedOption { - final String param1; - final String param2; + final String? param1; + final String? param2; final String myContextPath; ConvertedOption._(this.param1, this.param2, this.myContextPath); static ConvertedOption fromYamlMap(YamlMap yamlMap, String canonicalYamlPath, ResourceProvider resourceProvider) { - String p1; - String p2; + String? p1; + String? p2; for (var entry in yamlMap.entries) { switch (entry.key.toString()) { @@ -43,20 +41,19 @@ class ConvertedOption { void main() { var resourceProvider = pubPackageMetaProvider.resourceProvider; - DartdocOptionRoot dartdocOptionSetFiles; - DartdocOptionRoot dartdocOptionSetArgs; - DartdocOptionRoot dartdocOptionSetAll; - DartdocOptionRoot dartdocOptionSetSynthetic; - Folder tempDir; - Folder firstDir; - Folder secondDir; - Folder secondDirFirstSub; - Folder secondDirSecondSub; - - File dartdocOptionsOne; - File dartdocOptionsTwo; - File dartdocOptionsTwoFirstSub; - File firstExisting; + late final DartdocOptionRoot dartdocOptionSetFiles; + late final DartdocOptionRoot dartdocOptionSetArgs; + late final DartdocOptionRoot dartdocOptionSetAll; + late final DartdocOptionRoot dartdocOptionSetSynthetic; + late final Folder tempDir; + late final Folder firstDir; + late final Folder secondDir; + late final Folder secondDirFirstSub; + late final Folder secondDirSecondSub; + + late final File dartdocOptionsOne; + late final File dartdocOptionsTwo; + late final File firstExisting; setUpAll(() { dartdocOptionSetSynthetic = DartdocOptionRoot('dartdoc', resourceProvider); @@ -98,24 +95,24 @@ void main() { dartdocOptionSetFiles.add(DartdocOptionFileOnly>( 'fileOptionList', [], resourceProvider, optionIs: OptionKind.file, mustExist: true)); - dartdocOptionSetFiles.add(DartdocOptionFileOnly( + dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'fileOption', null, resourceProvider, optionIs: OptionKind.file, mustExist: true)); dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'parentOverride', 'oops', resourceProvider, parentDirOverridesChild: true)); - dartdocOptionSetFiles.add(DartdocOptionFileOnly( + dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'nonCriticalFileOption', null, resourceProvider, optionIs: OptionKind.file)); dartdocOptionSetFiles.add(DartdocOptionSet('nestedOption', resourceProvider) ..addAll([DartdocOptionFileOnly('flag', false, resourceProvider)])); - dartdocOptionSetFiles.add(DartdocOptionFileOnly( + dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'dirOption', null, resourceProvider, optionIs: OptionKind.dir, mustExist: true)); - dartdocOptionSetFiles.add(DartdocOptionFileOnly( + dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'nonCriticalDirOption', null, resourceProvider, optionIs: OptionKind.dir)); - dartdocOptionSetFiles.add(DartdocOptionFileOnly( + dartdocOptionSetFiles.add(DartdocOptionFileOnly( 'convertThisMap', null, resourceProvider, @@ -166,7 +163,7 @@ void main() { 'mapOption', {'hi': 'there'}, resourceProvider)); dartdocOptionSetAll.add(DartdocOptionArgFile( 'notInAnyFile', 'so there', resourceProvider)); - dartdocOptionSetAll.add(DartdocOptionArgFile( + dartdocOptionSetAll.add(DartdocOptionArgFile( 'fileOption', null, resourceProvider, optionIs: OptionKind.file, mustExist: true)); dartdocOptionSetAll.add(DartdocOptionArgFile>( @@ -202,7 +199,7 @@ void main() { .join(firstDir.path, 'dartdoc_options.yaml')); dartdocOptionsTwo = resourceProvider.getFile(resourceProvider.pathContext .join(secondDir.path, 'dartdoc_options.yaml')); - dartdocOptionsTwoFirstSub = resourceProvider.getFile(resourceProvider + var dartdocOptionsTwoFirstSub = resourceProvider.getFile(resourceProvider .pathContext .join(secondDirFirstSub.path, 'dartdoc_options.yaml')); @@ -265,7 +262,7 @@ dartdoc: dartdocOptionSetSynthetic['vegetableLoaderChecked'].valueAt(firstDir), orderedEquals([path.canonicalize(firstExisting.path)])); - String errorMessage; + String? errorMessage; try { dartdocOptionSetSynthetic['vegetableLoaderChecked'].valueAt(tempDir); } on DartdocFileMissing catch (e) { @@ -313,7 +310,7 @@ dartdoc: () { dartdocOptionSetAll .parseArguments(['--file-option', 'override-not-existing.dart']); - String errorMessage; + String? errorMessage; try { dartdocOptionSetAll['fileOption'].valueAt(firstDir); } on DartdocFileMissing catch (e) { @@ -338,7 +335,7 @@ dartdoc: test('File errors still get passed through', () { dartdocOptionSetAll.parseArguments([]); - String errorMessage; + String? errorMessage; try { dartdocOptionSetAll['fileOption'].valueAt(secondDir); } on DartdocFileMissing catch (e) { @@ -456,7 +453,7 @@ dartdoc: }); test('DartdocOptionArgOnly checks file existence', () { - String errorMessage; + String? errorMessage; dartdocOptionSetArgs.parseArguments(['--single-file', 'not_found.txt']); try { dartdocOptionSetArgs['singleFile'].valueAt(tempDir); @@ -474,7 +471,7 @@ dartdoc: }); test('DartdocOptionArgOnly checks file existence on multi-options', () { - String errorMessage; + String? errorMessage; dartdocOptionSetArgs.parseArguments([ '--files-flag', resourceProvider.pathContext.absolute(firstExisting.path), @@ -571,7 +568,7 @@ dartdoc: test('DartdocOptionArgOnly throws on double type mismatch', () { dartdocOptionSetArgs.parseArguments(['--respawn-probability', 'unknown']); - String errorMessage; + String? errorMessage; try { dartdocOptionSetArgs['respawnProbability'].valueAt(tempDir); } on DartdocOptionError catch (e) { @@ -587,7 +584,7 @@ dartdoc: dartdocOptionSetArgs.parseArguments(['--number-of-heads', '3.6']); expect(() => dartdocOptionSetArgs['number_of_heads'].valueAt(tempDir), throwsA(const TypeMatcher())); - String errorMessage; + String? errorMessage; try { dartdocOptionSetArgs['number_of_heads'].valueAt(tempDir); } on DartdocOptionError catch (e) { @@ -602,7 +599,7 @@ dartdoc: test('DartdocOptionArgOnly throws on a map type mismatch', () { dartdocOptionSetArgs .parseArguments(['--a-fancy-map-variable', 'not a map']); - String errorMessage; + String? errorMessage; try { dartdocOptionSetArgs['aFancyMapVariable'].valueAt(tempDir); } on DartdocOptionError catch (e) { @@ -628,7 +625,7 @@ dartdoc: }); test('DartdocOptionSetFile checks file existence when appropriate', () { - String errorMessage; + String? errorMessage; try { dartdocOptionSetFiles['fileOptionList'].valueAt(secondDir); } on DartdocFileMissing catch (e) { @@ -654,7 +651,7 @@ dartdoc: test( 'DartdocOptionSetFile resolves paths for files relative to where they are declared', () { - String errorMessage; + String? errorMessage; try { dartdocOptionSetFiles['fileOption'].valueAt(secondDirFirstSub); } on DartdocFileMissing catch (e) { @@ -681,7 +678,7 @@ dartdoc: test('DartdocOptionSetFile checks errors for directory options', () { expect(dartdocOptionSetFiles['dirOption'].valueAt(secondDir), equals(path.canonicalize(path.join(secondDir.path, 'firstSub')))); - String errorMessage; + String? errorMessage; try { dartdocOptionSetFiles['dirOption'].valueAt(firstDir); } on DartdocFileMissing catch (e) { diff --git a/test/end2end/dartdoc_integration_test.dart b/test/end2end/dartdoc_integration_test.dart index b5e9eb825c..6c0334ff8d 100644 --- a/test/end2end/dartdoc_integration_test.dart +++ b/test/end2end/dartdoc_integration_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.dartdoc_integration_test; import 'dart:async'; @@ -18,7 +16,7 @@ import '../../tool/subprocess_launcher.dart'; import '../src/utils.dart'; Uri get _currentFileUri => - (reflect(main) as ClosureMirror).function.location.sourceUri; + (reflect(main) as ClosureMirror).function.location!.sourceUri; String get _testPackagePath => path.fromUri(_currentFileUri.resolve('../../testing/test_package')); String get _testPackageFlutterPluginPath => path.fromUri(_currentFileUri @@ -29,8 +27,8 @@ String get _testPackageMinimumPath => void main() { group('Invoking command-line dartdoc', () { var dartdocPath = path.canonicalize(path.join('bin', 'dartdoc.dart')); - CoverageSubprocessLauncher subprocessLauncher; - Directory tempDir; + late final CoverageSubprocessLauncher subprocessLauncher; + late final Directory tempDir; setUpAll(() async { tempDir = @@ -181,7 +179,7 @@ void main() { await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args, workingDirectory: _testPackagePath, perLine: (s) => output.writeln(s)); - var dartdocMeta = pubPackageMetaProvider.fromFilename(dartdocPath); + var dartdocMeta = pubPackageMetaProvider.fromFilename(dartdocPath)!; expect(output.toString(), endsWith('dartdoc version: ${dartdocMeta.version}\n')); }); @@ -238,9 +236,9 @@ void main() { var footerRegex = RegExp(r'
(.*\s*?\n?)+?
', multiLine: true); // get footer, check for version number - var m = footerRegex.firstMatch(outFile.readAsStringSync()); + var m = footerRegex.firstMatch(outFile.readAsStringSync())!; var version = RegExp(r'(\d+\.)?(\d+\.)?(\*|\d+)'); - expect(version.hasMatch(m.group(0)), false); + expect(version.hasMatch(m.group(0)!), false); }); }, timeout: Timeout.factor(8)); } diff --git a/test/end2end/dartdoc_test.dart b/test/end2end/dartdoc_test.dart index 6bd932cdb1..b7a1471191 100644 --- a/test/end2end/dartdoc_test.dart +++ b/test/end2end/dartdoc_test.dart @@ -1,9 +1,6 @@ // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: non_constant_identifier_names - -// @dart=2.9 library dartdoc.dartdoc_test; @@ -81,7 +78,7 @@ class DartdocLoggingOptionContext extends DartdocGeneratorOptionContext void main() { group('dartdoc with generators', () { - Folder tempDir; + late Folder tempDir; setUpAll(() async { var optionSet = await DartdocOptionRoot.fromOptionGenerators( @@ -117,15 +114,15 @@ void main() { group('Option handling', () { Dartdoc dartdoc; - DartdocResults results; - PackageGraph p; - Folder tempDir; + late DartdocResults results; + late PackageGraph packageGraph; + late Folder tempDir; setUpAll(() async { tempDir = _resourceProvider.createSystemTemp('dartdoc.test.'); dartdoc = await buildDartdoc([], _testPackageOptions, tempDir); results = await dartdoc.generateDocsBase(); - p = results.packageGraph; + packageGraph = results.packageGraph; }); test('generator parameters', () async { @@ -142,17 +139,17 @@ void main() { }); test('examplePathPrefix', () async { - var UseAnExampleHere = p.allCanonicalModelElements + var classUseAnExampleHere = packageGraph.allCanonicalModelElements .whereType() .firstWhere((ModelElement c) => c.name == 'UseAnExampleHere'); expect( - UseAnExampleHere.documentationAsHtml, + classUseAnExampleHere.documentationAsHtml, contains( 'An example of an example in an unusual example location.')); }); test('includeExternal and showUndocumentedCategories', () async { - var withUndocumentedCategory = p.allCanonicalModelElements + var withUndocumentedCategory = packageGraph.allCanonicalModelElements .whereType() .firstWhere((ModelElement c) => c.name == 'UseAnExampleHere'); expect(withUndocumentedCategory.isPublic, isTrue); @@ -247,8 +244,8 @@ void main() { }); group('validate basic doc generation', () { - DartdocResults results; - Folder tempDir; + late final DartdocResults results; + late final Folder tempDir; setUpAll(() async { tempDir = _resourceProvider.createSystemTemp('dartdoc.test.'); @@ -314,9 +311,10 @@ void main() { expect(p.libraries.map((lib) => lib.name).contains('dart:async'), isTrue); expect(p.libraries.map((lib) => lib.name).contains('dart:bear'), isTrue); expect(p.packageMap.length, equals(2)); + var dartPackage = p.packageMap['Dart']!; // Things that do not override the core SDK belong in their own package. - expect(p.packageMap['Dart'].isSdk, isTrue); - expect(p.packageMap['sky_engine'].isSdk, isFalse); + expect(dartPackage.isSdk, isTrue); + expect(p.packageMap['sky_engine']!.isSdk, isFalse); // Should be true once dart-lang/sdk#32707 is fixed. //expect( // p.publicLibraries, @@ -324,11 +322,11 @@ void main() { // (l.element as LibraryElement).isInSdk == l.packageMeta.isSdk)); // Ensure that we actually parsed some source by checking for // the 'Bear' class. - var dart_bear = p.packageMap['Dart'].libraries - .firstWhere((lib) => lib.name == 'dart:bear'); + var dartBear = + dartPackage.libraries.firstWhere((lib) => lib.name == 'dart:bear'); expect( - dart_bear.allClasses.map((cls) => cls.name).contains('Bear'), isTrue); - expect(p.packageMap['Dart'].publicLibraries, hasLength(3)); + dartBear.allClasses.map((cls) => cls.name).contains('Bear'), isTrue); + expect(dartPackage.publicLibraries, hasLength(3)); }); test('generate docs with custom templates', () async { diff --git a/test/end2end/model_special_cases_test.dart b/test/end2end/model_special_cases_test.dart index 725b0b96d7..b840b7fbb9 100644 --- a/test/end2end/model_special_cases_test.dart +++ b/test/end2end/model_special_cases_test.dart @@ -3,16 +3,12 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: non_constant_identifier_names -// @dart=2.9 - /// This test library handles checks against the model for configurations /// that require different PackageGraph configurations. Since those /// take a long time to initialize, isolate them here to keep model_test /// fast. library dartdoc.model_special_cases_test; -import 'dart:io'; - import 'package:async/async.dart'; import 'package:dartdoc/src/matching_link_result.dart'; import 'package:dartdoc/src/model/model.dart'; @@ -64,13 +60,6 @@ Future _bootSdkPackage() async { } void main() { - var sdkDir = pubPackageMetaProvider.defaultSdkDir; - - if (sdkDir == null) { - print('Warning: unable to locate the Dart SDK.'); - exit(1); - } - // We can not use ExperimentalFeature.releaseVersion or even // ExperimentalFeature.experimentalReleaseVersion as these are set to null // even when partial analyzer implementations are available, and are often @@ -82,11 +71,11 @@ void main() { // block when the feature is enabled by default. group('Experiments', () { group('constructor-tearoffs', () { - Library constructorTearoffs; - Class A, B, C, D, E, F; - Mixin M; - Typedef At, Bt, Ct, Et, Ft, NotAClass; - Constructor Anew, Bnew, Cnew, Dnew, Enew, Fnew; + late final Library constructorTearoffs; + late final Class A, B, C, D, E, F; + late final Mixin M; + late final Typedef At, Bt, Ct, Et, Ft, NotAClass; + late final Constructor Anew, Bnew, Cnew, Dnew, Enew, Fnew; setUpAll(() async { constructorTearoffs = (await _testPackageGraphExperiments) @@ -106,12 +95,12 @@ void main() { Ft = constructorTearoffs.typedefs.firstWhere((t) => t.name == 'Ft'); NotAClass = constructorTearoffs.typedefs .firstWhere((t) => t.name == 'NotAClass'); - Anew = A.unnamedConstructor; - Bnew = B.unnamedConstructor; - Cnew = C.unnamedConstructor; - Dnew = D.unnamedConstructor; - Enew = E.unnamedConstructor; - Fnew = F.unnamedConstructor; + Anew = A.unnamedConstructor!; + Bnew = B.unnamedConstructor!; + Cnew = C.unnamedConstructor!; + Dnew = D.unnamedConstructor!; + Enew = E.unnamedConstructor!; + Fnew = F.unnamedConstructor!; }); test('smoke test', () { @@ -279,8 +268,8 @@ void main() { group('HTML is sanitized when enabled', () { Class classWithHtml; - Method blockHtml; - Method inlineHtml; + late final Method blockHtml; + late final Method inlineHtml; PackageGraph packageGraph; Library exLibrary; @@ -331,11 +320,11 @@ void main() { group('HTML Injection when allowed', () { Class htmlInjection; - Method injectSimpleHtml; - Method injectHtmlFromTool; + late final Method injectSimpleHtml; + late final Method injectHtmlFromTool; PackageGraph injectionPackageGraph; - Library injectionExLibrary; + late final Library injectionExLibrary; setUpAll(() async { injectionPackageGraph = await utils.bootBasicPackage( @@ -397,7 +386,7 @@ void main() { }); group('Missing and Remote', () { - PackageGraph ginormousPackageGraph; + late final PackageGraph ginormousPackageGraph; setUpAll(() async { ginormousPackageGraph = await _testPackageGraphGinormous; @@ -430,7 +419,7 @@ void main() { }); group('Category', () { - PackageGraph ginormousPackageGraph; + late final PackageGraph ginormousPackageGraph; setUpAll(() async { ginormousPackageGraph = await _testPackageGraphGinormous; @@ -496,7 +485,7 @@ void main() { }); group('Package', () { - PackageGraph sdkAsPackageGraph; + late final PackageGraph sdkAsPackageGraph; setUpAll(() async { sdkAsPackageGraph = await _testPackageGraphSdk; @@ -516,7 +505,7 @@ void main() { // If this fails, EventTarget might have been changed to no longer // inherit from Interceptor. If that's true, adjust test case to // another class that does. - expect(hashCode.inheritance.any((c) => c.name == 'Interceptor'), isTrue); + expect(hashCode.inheritance.any((c) => c?.name == 'Interceptor'), isTrue); // If EventTarget really does start implementing hashCode, this will // fail. expect(hashCode.href, diff --git a/test/package_test.dart b/test/package_test.dart index 754bab92d5..e71c850e07 100644 --- a/test/package_test.dart +++ b/test/package_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/file_system/memory_file_system.dart'; import 'package:dartdoc/src/dartdoc_options.dart'; @@ -16,14 +14,14 @@ import 'package:test/test.dart'; import 'src/utils.dart' as utils; void main() { - MemoryResourceProvider resourceProvider; - PackageMetaProvider packageMetaProvider; - FakePackageConfigProvider packageConfigProvider; - DartdocOptionSet optionSet; - Folder sdkFolder; - - Folder projectRoot; - String projectPath; + late MemoryResourceProvider resourceProvider; + late PackageMetaProvider packageMetaProvider; + late FakePackageConfigProvider packageConfigProvider; + late DartdocOptionSet optionSet; + late Folder sdkFolder; + + late Folder projectRoot; + late String projectPath; var packageName = 'my_package'; void writeToJoinedPath(List pathSegments, String content) { @@ -37,17 +35,17 @@ void main() { setUp(() async { packageMetaProvider = utils.testPackageMetaProvider; - resourceProvider = packageMetaProvider.resourceProvider; + resourceProvider = + packageMetaProvider.resourceProvider as MemoryResourceProvider; sdkFolder = packageMetaProvider.defaultSdkDir; optionSet = await DartdocOptionRoot.fromOptionGenerators( 'dartdoc', [createDartdocOptions], packageMetaProvider); - packageConfigProvider = utils.getTestPackageConfigProvider(sdkFolder.path); + packageConfigProvider = utils.getTestPackageConfigProvider(sdkFolder.path) + as FakePackageConfigProvider; }); tearDown(() { - projectRoot = null; - projectPath = null; clearPackageMetaCache(); }); @@ -248,8 +246,8 @@ library bar; }); group('using --link-to-remote', () { - Folder packageOneRoot; - Folder packageTwoRoot; + late Folder packageOneRoot; + late Folder packageTwoRoot; setUp(() { optionSet.parseArguments(['--link-to-remote']); @@ -425,7 +423,7 @@ dartdoc: ]); var pragmaModelElement = - packageGraph.specialClasses[SpecialClass.pragma]; + packageGraph.specialClasses[SpecialClass.pragma]!; expect(pragmaModelElement.name, equals('pragma')); }); }); diff --git a/test/warnings_test.dart b/test/warnings_test.dart index e4abd2320a..d1e603fb53 100644 --- a/test/warnings_test.dart +++ b/test/warnings_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - /// Unit tests for lib/src/warnings.dart. library dartdoc.warnings_test; @@ -16,9 +14,9 @@ import 'package:dartdoc/src/warnings.dart'; import 'package:test/test.dart'; void main() { - ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; - Folder testPackageOne, testPackageTwo, testPackageThree; - DartdocOptionSet optionSet; + var resourceProvider = PhysicalResourceProvider.INSTANCE; + late final Folder testPackageOne, testPackageTwo, testPackageThree; + late DartdocOptionSet optionSet; setUpAll(() { var tempDir = resourceProvider.createSystemTemp('warnings_test'); diff --git a/tool/grind.dart b/tool/grind.dart index 9f17a0ab28..050bfdeb88 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -411,12 +411,12 @@ class WarningsCollection { /// Returns a map of warning texts to the number of times each has been seen. WarningsCollection jsonMessageIterableToWarnings( - Iterable> messageIterable, + Iterable> messageIterable, String tempPath, String? pubDir, String branch) { var warningTexts = WarningsCollection(tempPath, pubDir, branch); - for (Map message in messageIterable) { + for (Map message in messageIterable) { if (message.containsKey('level') && message['level'] == 'WARNING' && message.containsKey('data')) { @@ -532,7 +532,7 @@ Future testWithAnalyzerSdk() async { } } -Future>> _buildSdkDocs( +Future>> _buildSdkDocs( String sdkDocsPath, Future futureCwd, [String label = '']) async { if (label != '') label = '-$label'; @@ -554,7 +554,7 @@ Future>> _buildSdkDocs( workingDirectory: cwd); } -Future>> _buildTestPackageDocs( +Future>> _buildTestPackageDocs( String outputDir, String cwd, {List params = const [], String label = '', @@ -905,7 +905,7 @@ class FlutterRepo { } } -Future>> _buildFlutterDocs( +Future>> _buildFlutterDocs( String flutterPath, Future futureCwd, Map env, [String? label]) async { var flutterRepo = await FlutterRepo.copyFromExistingFlutterRepo( diff --git a/tool/subprocess_launcher.dart b/tool/subprocess_launcher.dart index 92b6480266..7ca5ec95dd 100644 --- a/tool/subprocess_launcher.dart +++ b/tool/subprocess_launcher.dart @@ -25,7 +25,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher { /// A list of all coverage results picked up by all launchers. // TODO(srawlins): Refactor this to one or more type aliases once the feature // is enabled. - static List>>> coverageResults = []; + static List>>> coverageResults = []; static Directory tempDir = () { var coverageData = Platform.environment['DARTDOC_COVERAGE_DATA']; @@ -67,7 +67,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher { } @override - Future>> runStreamed( + Future>> runStreamed( String executable, List arguments, {String? workingDirectory, Map? environment, @@ -91,7 +91,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher { } } - Completer>> coverageResult = Completer(); + Completer>> coverageResult = Completer(); if (coverageEnabled) { // This must be added before awaiting in this method. @@ -164,7 +164,7 @@ class SubprocessLauncher { /// Windows (though some of the bashisms will no longer make sense). /// TODO(jcollins-g): refactor to return a stream of stderr/stdout lines /// and their associated JSON objects. - Future>> runStreamed( + Future>> runStreamed( String executable, List arguments, {String? workingDirectory, Map? environment, @@ -173,21 +173,23 @@ class SubprocessLauncher { environment = {} ..addAll(environmentDefaults) ..addAll(environment ?? {}); - List> jsonObjects = []; + List> jsonObjects = []; /// Allow us to pretend we didn't pass the JSON flag in to dartdoc by /// printing what dartdoc would have printed without it, yet storing /// json objects into [jsonObjects]. Iterable jsonCallback(String line) { if (perLine != null) perLine(line); - Map? result; + Map? result; try { result = json.decoder.convert(line); } on FormatException { // Assume invalid JSON is actually a line of normal text. - } on TypeError { + } on TypeError catch (e, st) { // The convert function returns a String if there is no JSON in the // line. Just ignore it and leave result null. + print(e); + print(st); } if (result != null) { jsonObjects.add(result);