From 78a39b0596a0ff2e0bcfb2350f5cd0c027327c06 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Mon, 14 Aug 2023 04:01:56 -0500 Subject: [PATCH] Fix some type related lints (#3986) --- analysis_options.yaml | 3 +++ lib/src/command.dart | 2 +- lib/src/command/add.dart | 2 +- lib/src/command/cache_preload.dart | 4 +-- lib/src/command/deps.dart | 4 ++- lib/src/command/uploader.dart | 2 +- lib/src/command_runner.dart | 2 +- lib/src/exceptions.dart | 4 +-- lib/src/flutter_releases.dart | 2 +- lib/src/global_packages.dart | 10 ++++---- lib/src/log.dart | 10 +++----- lib/src/package_name.dart | 6 ++--- lib/src/pub_embeddable_command.dart | 2 +- lib/src/pubspec.dart | 6 ++--- lib/src/pubspec_utils.dart | 2 +- lib/src/source.dart | 13 +++++++--- lib/src/source/git.dart | 4 +-- lib/src/source/hosted.dart | 4 +-- lib/src/source/path.dart | 4 +-- lib/src/source/root.dart | 4 +-- lib/src/source/sdk.dart | 4 +-- lib/src/source/unknown.dart | 7 +++--- lib/src/utils.dart | 6 ++--- lib/src/validator/strict_dependencies.dart | 3 +-- test/descriptor.dart | 4 +-- .../get_executable_for_command_test.dart | 10 ++++---- test/package_server.dart | 2 +- test/pinned_dependency_hint_test.dart | 2 +- test/test_pub.dart | 25 +------------------ test/validator/dependency_override_test.dart | 2 +- test/validator/dependency_test.dart | 12 ++++----- test/validator/file_case_test.dart | 2 +- test/validator/flutter_constraint_test.dart | 2 +- test/validator/gitignore_test.dart | 2 +- test/validator/utils.dart | 24 ++++++++++-------- test/version_solver_test.dart | 4 +-- 36 files changed, 95 insertions(+), 106 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 4c23fc5d3..ecd780288 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -14,6 +14,7 @@ analyzer: linter: rules: + - always_declare_return_types - avoid_catching_errors - avoid_print - avoid_private_typedef_functions @@ -26,6 +27,7 @@ linter: - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_runtimeType_toString + - omit_local_variable_types - only_throw_errors - package_api_docs - prefer_asserts_in_initializer_lists @@ -36,6 +38,7 @@ linter: - sort_pub_dependencies - test_types_in_equals - throw_in_finally + - type_annotate_public_apis - unawaited_futures - unnecessary_lambdas - unnecessary_null_aware_assignments diff --git a/lib/src/command.dart b/lib/src/command.dart index 29945020c..49c69adff 100644 --- a/lib/src/command.dart +++ b/lib/src/command.dart @@ -354,7 +354,7 @@ abstract class PubTopLevel { log.Verbosity get verbosity; bool get trace; - static addColorFlag(ArgParser argParser) { + static void addColorFlag(ArgParser argParser) { argParser.addFlag( 'color', help: 'Use colors in terminal output.\n' diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index e436b2c01..8f296e283 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart @@ -684,7 +684,7 @@ Specify multiple sdk packages with descriptors.'''); final name = ref.name; final resultId = resultPackages.firstWhere((id) => id.name == name); - Object? description = pubspecDescription( + final description = pubspecDescription( ref.withConstraint( constraint ?? (ref.source is HostedSource diff --git a/lib/src/command/cache_preload.dart b/lib/src/command/cache_preload.dart index 54b7867d5..0acb03c44 100644 --- a/lib/src/command/cache_preload.dart +++ b/lib/src/command/cache_preload.dart @@ -33,12 +33,12 @@ class CachePreloadCommand extends PubCommand { usageException('No package to preload given.'); } - for (String packagePath in argResults.rest) { + for (final packagePath in argResults.rest) { if (!fileExists(packagePath)) { fail('Could not find file $packagePath.'); } } - for (String archivePath in argResults.rest) { + for (final archivePath in argResults.rest) { final id = await cache.hosted.preloadPackage(archivePath, cache); final url = (id.description.description as HostedDescription).url; diff --git a/lib/src/command/deps.dart b/lib/src/command/deps.dart index e082b14ab..0373ed6da 100644 --- a/lib/src/command/deps.dart +++ b/lib/src/command/deps.dart @@ -282,7 +282,9 @@ class DepsCommand extends PubCommand { buffer.writeln('- ${_labelPackage(package)}'); for (var dep in package.dependencies.values) { - buffer.writeln(' - ${log.bold(dep.name)} ${log.gray(dep.constraint)}'); + buffer.writeln( + ' - ${log.bold(dep.name)} ${log.gray(dep.constraint.toString())}', + ); } } } diff --git a/lib/src/command/uploader.dart b/lib/src/command/uploader.dart index e661d7247..c3ff77272 100644 --- a/lib/src/command/uploader.dart +++ b/lib/src/command/uploader.dart @@ -47,7 +47,7 @@ class UploaderCommand extends PubCommand { @override Future runProtected() async { - String packageName = ''; + var packageName = ''; try { packageName = entrypoint.root.name; } on Exception catch (_) { diff --git a/lib/src/command_runner.dart b/lib/src/command_runner.dart index 8c7f13420..65af797dd 100644 --- a/lib/src/command_runner.dart +++ b/lib/src/command_runner.dart @@ -209,7 +209,7 @@ class PubCommandRunner extends CommandRunner implements PubTopLevel { if (depsRev == actualRev) return; log.warning("${log.yellow('Warning:')} the revision of pub in DEPS is " - '${log.bold(depsRev)},\n' + '${log.bold(depsRev.toString())},\n' 'but ${log.bold(actualRev)} is checked out in ' '${p.relative(pubRoot)}.\n\n'); } diff --git a/lib/src/exceptions.dart b/lib/src/exceptions.dart index f715b10a1..e4a1e250b 100644 --- a/lib/src/exceptions.dart +++ b/lib/src/exceptions.dart @@ -115,7 +115,7 @@ class PackageIntegrityException extends PubHttpException { /// Returns whether [error] is a user-facing error object. /// /// This includes both [ApplicationException] and any dart:io errors. -bool isUserFacingException(error) { +bool isUserFacingException(Object error) { return error is ApplicationException || error is AnalyzerErrorGroup || error is IsolateSpawnException || @@ -148,7 +148,7 @@ class SourceSpanApplicationException extends SourceSpanFormatException }) : super(message, span); @override - String toString({color}) { + String toString({Object? color}) { return [ if (explanation != null) explanation, span == null diff --git a/lib/src/flutter_releases.dart b/lib/src/flutter_releases.dart index 20752a409..904f8db2a 100644 --- a/lib/src/flutter_releases.dart +++ b/lib/src/flutter_releases.dart @@ -100,6 +100,6 @@ class FlutterRelease { required this.channel, }); @override - toString() => + String toString() => 'FlutterRelease(flutter=$flutterVersion, dart=$dartVersion, channel=$channel)'; } diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index 2c44d5b3f..a94209efe 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -214,7 +214,7 @@ class GlobalPackages { bool silent = false, }) async { final name = dep.name; - LockFile? originalLockFile = _describeActive(name, cache); + final originalLockFile = _describeActive(name, cache); // Create a dummy package with just [dep] so we can do resolution on it. var root = Package.inMemory( @@ -251,7 +251,7 @@ class GlobalPackages { final sameVersions = originalLockFile != null && originalLockFile.samePackageIds(lockFile); - final PackageId id = lockFile.packages[name]!; + final id = lockFile.packages[name]!; if (sameVersions) { log.message(''' The package $name is already activated at newest available version. @@ -331,7 +331,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam '"${description.path}".'); } else { log.message('Package ${log.bold(name)} is currently active at version ' - '${log.bold(id.version)}.'); + '${log.bold(id.version.toString())}.'); } return lockFile; } @@ -724,10 +724,10 @@ try: for (var command in ordered(collided.keys)) { if (overwriteBinStubs) { log.warning('Replaced ${log.bold(command)} previously installed from ' - '${log.bold(collided[command])}.'); + '${log.bold(collided[command].toString())}.'); } else { log.warning('Executable ${log.bold(command)} was already installed ' - 'from ${log.bold(collided[command])}.'); + 'from ${log.bold(collided[command].toString())}.'); } } diff --git a/lib/src/log.dart b/lib/src/log.dart index 35870e4d3..8dc835ed9 100644 --- a/lib/src/log.dart +++ b/lib/src/log.dart @@ -204,7 +204,7 @@ class _Entry { /// /// If [error] is passed, it's appended to [message]. If [trace] is passed, it's /// printed at log level fine. -void error(String message, [error, StackTrace? trace]) { +void error(String message, [Object? error, StackTrace? trace]) { if (error != null) { message = message.isEmpty ? '$error' : '$message: $error'; if (error is Error && trace == null) trace = error.stackTrace; @@ -490,15 +490,13 @@ void unmuteProgress() { /// that supports that. /// /// Use this to highlight the most important piece of a long chunk of text. -String bold(text) => '$_bold$text$_none'; +String bold(String text) => '$_bold$text$_none'; /// Wraps [text] in the ANSI escape codes to make it gray when on a platform /// that supports that. /// /// Use this for text that's less important than the text around it. -String gray(text) { - return '$_gray$text$_none'; -} +String gray(String text) => '$_gray$text$_none'; /// Wraps [text] in the ANSI escape codes to color it cyan when on a platform /// that supports that. @@ -626,7 +624,7 @@ class _JsonLogger { } /// Encodes [message] to JSON and prints it if JSON output is enabled. - void message(message) { + void message(Map message) { if (!enabled) return; stdout.writeln(jsonEncode(message)); diff --git a/lib/src/package_name.dart b/lib/src/package_name.dart index af1a24cd1..f3aff59b2 100644 --- a/lib/src/package_name.dart +++ b/lib/src/package_name.dart @@ -49,7 +49,7 @@ class PackageRef { PackageRange(this, constraint); @override - bool operator ==(other) => + bool operator ==(Object other) => other is PackageRef && name == other.name && description == other.description; @@ -95,7 +95,7 @@ class PackageId { int get hashCode => Object.hash(name, version, description); @override - bool operator ==(other) => + bool operator ==(Object other) => other is PackageId && name == other.name && version == other.version && @@ -208,7 +208,7 @@ class PackageRange { int get hashCode => Object.hash(_ref, constraint); @override - bool operator ==(other) => + bool operator ==(Object other) => other is PackageRange && _ref == other._ref && other.constraint == constraint; diff --git a/lib/src/pub_embeddable_command.dart b/lib/src/pub_embeddable_command.dart index 06bba9e70..b12b70db9 100644 --- a/lib/src/pub_embeddable_command.dart +++ b/lib/src/pub_embeddable_command.dart @@ -49,7 +49,7 @@ class PubEmbeddableCommand extends PubCommand implements PubTopLevel { String get name => 'pub'; @override - get suggestionAliases => const ['packages', 'pkg']; + List get suggestionAliases => const ['packages', 'pkg']; @override String get description => 'Work with packages.'; diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index 2413f0ded..f1ec4729d 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -225,7 +225,7 @@ class Pubspec extends PubspecBase { pubspecPath, ); } - String? overridesFileContents = + final overridesFileContents = allowOverridesFile && fileExists(overridesPath) ? readTextFile(overridesPath) : null; @@ -613,7 +613,7 @@ class SdkConstraint { VersionConstraint originalConstraint, { required VersionConstraint? defaultUpperBoundConstraint, }) { - VersionConstraint constraint = originalConstraint; + var constraint = originalConstraint; if (defaultUpperBoundConstraint != null && constraint is VersionRange && constraint.max == null && @@ -676,7 +676,7 @@ class SdkConstraint { } @override - operator ==(other) => + bool operator ==(Object other) => other is SdkConstraint && other.effectiveConstraint == effectiveConstraint && other.originalConstraint == originalConstraint; diff --git a/lib/src/pubspec_utils.dart b/lib/src/pubspec_utils.dart index 5a19f118a..3259d6e19 100644 --- a/lib/src/pubspec_utils.dart +++ b/lib/src/pubspec_utils.dart @@ -159,7 +159,7 @@ VersionConstraint stripUpperBound(VersionConstraint constraint) { /// /// The syntax used for hosted will depend on the language version of /// [relativeEntrypoint] -Object? pubspecDescription( +Object pubspecDescription( PackageRange range, SystemCache cache, Entrypoint relativeEntrypoint, diff --git a/lib/src/source.dart b/lib/src/source.dart index e5063d3f8..baa87c24f 100644 --- a/lib/src/source.dart +++ b/lib/src/source.dart @@ -4,6 +4,7 @@ import 'dart:async'; +import 'package:meta/meta.dart'; import 'package:pub_semver/pub_semver.dart'; import 'exceptions.dart'; @@ -78,7 +79,7 @@ abstract class Source { /// Throws a [FormatException] if the description is not valid. PackageRef parseRef( String name, - description, { + Object? description, { String? containingDir, required LanguageVersion languageVersion, }); @@ -96,7 +97,7 @@ abstract class Source { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }); @@ -183,10 +184,12 @@ abstract class Description { String format(); @override - bool operator ==(other) => + @mustBeOverridden + bool operator ==(Object other) => throw UnimplementedError('Subclasses must override'); @override + @mustBeOverridden int get hashCode => throw UnimplementedError('Subclasses must override'); } @@ -214,10 +217,12 @@ abstract class ResolvedDescription { String format() => description.format(); @override - bool operator ==(other) => + @mustBeOverridden + bool operator ==(Object other) => throw UnimplementedError('Subclasses must override'); @override + @mustBeOverridden int get hashCode => throw UnimplementedError('Subclasses must override'); } diff --git a/lib/src/source/git.dart b/lib/src/source/git.dart index cc6920695..93a2a0a66 100644 --- a/lib/src/source/git.dart +++ b/lib/src/source/git.dart @@ -86,7 +86,7 @@ class GitSource extends CachedSource { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }) { if (description is! Map) { @@ -357,7 +357,7 @@ class GitSource extends CachedSource { SystemCache cache, ) async { return await _pool.withResource(() async { - bool didUpdate = false; + var didUpdate = false; final ref = id.toRef(); final description = ref.description; if (description is! GitDescription) { diff --git a/lib/src/source/hosted.dart b/lib/src/source/hosted.dart index c7b769253..7ad18c696 100644 --- a/lib/src/source/hosted.dart +++ b/lib/src/source/hosted.dart @@ -225,7 +225,7 @@ class HostedSource extends CachedSource { @override PackageRef parseRef( String name, - description, { + Object? description, { String? containingDir, required LanguageVersion languageVersion, }) { @@ -239,7 +239,7 @@ class HostedSource extends CachedSource { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }) { // Old pub versions only wrote `description: ` into the lock file. diff --git a/lib/src/source/path.dart b/lib/src/source/path.dart index f11ee66c0..527efeecc 100644 --- a/lib/src/source/path.dart +++ b/lib/src/source/path.dart @@ -59,7 +59,7 @@ class PathSource extends Source { @override PackageRef parseRef( String name, - description, { + Object? description, { String? containingDir, LanguageVersion? languageVersion, }) { @@ -90,7 +90,7 @@ class PathSource extends Source { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }) { if (description is! Map) { diff --git a/lib/src/source/root.dart b/lib/src/source/root.dart index 425b9a4d9..f57056668 100644 --- a/lib/src/source/root.dart +++ b/lib/src/source/root.dart @@ -58,7 +58,7 @@ class RootSource extends Source { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }) { throw UnsupportedError('Trying to parse a root package description.'); @@ -67,7 +67,7 @@ class RootSource extends Source { @override PackageRef parseRef( String name, - description, { + Object? description, { String? containingDir, required LanguageVersion languageVersion, }) { diff --git a/lib/src/source/sdk.dart b/lib/src/source/sdk.dart index c48a46321..89c6223e2 100644 --- a/lib/src/source/sdk.dart +++ b/lib/src/source/sdk.dart @@ -28,7 +28,7 @@ class SdkSource extends Source { @override PackageRef parseRef( String name, - description, { + Object? description, { String? containingDir, LanguageVersion? languageVersion, }) { @@ -43,7 +43,7 @@ class SdkSource extends Source { PackageId parseId( String name, Version version, - description, { + Object? description, { String? containingDir, }) { if (description is! String) { diff --git a/lib/src/source/unknown.dart b/lib/src/source/unknown.dart index cfcda2997..ef9eb1a93 100644 --- a/lib/src/source/unknown.dart +++ b/lib/src/source/unknown.dart @@ -27,7 +27,8 @@ class UnknownSource extends Source { /// Two unknown sources are the same if their names are the same. @override - bool operator ==(other) => other is UnknownSource && other.name == name; + bool operator ==(Object other) => + other is UnknownSource && other.name == name; @override int get hashCode => name.hashCode; @@ -104,7 +105,7 @@ class UnknownDescription extends Description { } @override - operator ==(Object other) => + bool operator ==(Object other) => other is UnknownDescription && source.name == other.source.name && json.encode(description) == json.encode(other.description); @@ -125,7 +126,7 @@ class ResolvedUnknownDescription extends ResolvedDescription { } @override - operator ==(Object other) => + bool operator ==(Object other) => other is ResolvedUnknownDescription && description == other.description; @override diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 866567492..77372db63 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -126,7 +126,7 @@ class Pair { String toString() => '($first, $last)'; @override - bool operator ==(other) { + bool operator ==(Object other) { if (other is! Pair) return false; return other.first == first && other.last == last; } @@ -526,7 +526,7 @@ final _unquotableYamlString = RegExp(r'^[a-zA-Z_-][a-zA-Z_0-9-]*$'); /// Converts [data], which is a parsed YAML object, to a pretty-printed string, /// using indentation for maps. -String yamlToString(data) { +String yamlToString(Object? data) { var buffer = StringBuffer(); void stringify(bool isMapValue, String indent, data) { @@ -677,7 +677,7 @@ final _exceptionPrefix = RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); /// /// Many exceptions include the exception class name at the beginning of their /// [toString], so we remove that if it exists. -String getErrorMessage(error) => +String getErrorMessage(Object error) => error.toString().replaceFirst(_exceptionPrefix, ''); /// Returns whether [version1] and [version2] are the same, ignoring the diff --git a/lib/src/validator/strict_dependencies.dart b/lib/src/validator/strict_dependencies.dart index 50fd20814..bd1674e99 100644 --- a/lib/src/validator/strict_dependencies.dart +++ b/lib/src/validator/strict_dependencies.dart @@ -24,8 +24,7 @@ class StrictDependenciesValidator extends Validator { /// `package:` URLs are ignored. Iterable<_Usage> _findPackages(Iterable files) sync* { final packagePath = p.normalize(p.absolute(entrypoint.rootDir)); - final AnalysisContextManager analysisContextManager = - AnalysisContextManager(packagePath); + final analysisContextManager = AnalysisContextManager(packagePath); for (var file in files) { List directives; diff --git a/test/descriptor.dart b/test/descriptor.dart index bcca9a14e..4ab25e801 100644 --- a/test/descriptor.dart +++ b/test/descriptor.dart @@ -102,8 +102,8 @@ Descriptor appPubspec({Map? dependencies, Map? extras}) { FileDescriptor libPubspec( String name, String version, { - Map? deps, - Map? devDeps, + Map? deps, + Map? devDeps, String? sdk, Map? extras, }) { diff --git a/test/embedding/get_executable_for_command_test.dart b/test/embedding/get_executable_for_command_test.dart index 351b32748..fe49de861 100644 --- a/test/embedding/get_executable_for_command_test.dart +++ b/test/embedding/get_executable_for_command_test.dart @@ -18,9 +18,9 @@ Future testGetExecutable( String command, String root, { bool allowSnapshot = true, - executable, - packageConfig, - errorMessage, + Object? executable, + String? packageConfig, + Object? errorMessage, CommandResolutionIssue? issue, }) async { final cachePath = getPubTestEnvironment()['PUB_CACHE']; @@ -152,7 +152,7 @@ Future main() async { await servePackages(); // The solver uses word-wrapping in its error message, so we use \s to - // accomodate. + // accommodate. await testGetExecutable( 'bar/m.dart', d.path(appPath), @@ -189,7 +189,7 @@ Future main() async { await servePackages(); // The solver uses word-wrapping in its error message, so we use \s to - // accomodate. + // accommodate. await testGetExecutable( ':foo', d.path(appPath), diff --git a/test/package_server.dart b/test/package_server.dart index db3770520..33eec4470 100644 --- a/test/package_server.dart +++ b/test/package_server.dart @@ -312,7 +312,7 @@ class PackageServer { int? crc32c, String? md5 = '5f4dcc3b5aa765d61d8327deb882cf99', }) { - List header = []; + final header = []; if (crc32c != null) { final bytes = Uint8List(4)..buffer.asByteData().setUint32(0, crc32c); diff --git a/test/pinned_dependency_hint_test.dart b/test/pinned_dependency_hint_test.dart index 5e7efa5ea..33d7d6921 100644 --- a/test/pinned_dependency_hint_test.dart +++ b/test/pinned_dependency_hint_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; import 'descriptor.dart' as d; import 'test_pub.dart'; -main() { +void main() { test('Gives hint when solve failure concerns a pinned flutter package', () async { await d.dir('flutter', [ diff --git a/test/test_pub.dart b/test/test_pub.dart index 0f979b8bb..a1e860779 100644 --- a/test/test_pub.dart +++ b/test/test_pub.dart @@ -51,7 +51,7 @@ Matcher isUnminifiedDart2JSOutput = contains('// The code supports the following hooks'); /// Converts [value] into a YAML string. -String yaml(value) => jsonEncode(value); +String yaml(Object? value) => jsonEncode(value); /// The path of the package cache directory used for tests, relative to the /// sandbox directory. @@ -915,29 +915,6 @@ Future validatePackage(ValidatorCreator fn, int? size) async { return validator; } -/// A matcher that matches a Pair. -Matcher pairOf(firstMatcher, lastMatcher) => - _PairMatcher(wrapMatcher(firstMatcher), wrapMatcher(lastMatcher)); - -class _PairMatcher extends Matcher { - final Matcher _firstMatcher; - final Matcher _lastMatcher; - - _PairMatcher(this._firstMatcher, this._lastMatcher); - - @override - bool matches(item, Map matchState) { - if (item is! Pair) return false; - return _firstMatcher.matches(item.first, matchState) && - _lastMatcher.matches(item.last, matchState); - } - - @override - Description describe(Description description) { - return description.addAll('(', ', ', ')', [_firstMatcher, _lastMatcher]); - } -} - /// Returns a matcher that asserts that a string contains [times] distinct /// occurrences of [pattern], which must be a regular expression pattern. Matcher matchesMultiple(String pattern, int times) { diff --git a/test/validator/dependency_override_test.dart b/test/validator/dependency_override_test.dart index 817a8fbd4..a3fd574f2 100644 --- a/test/validator/dependency_override_test.dart +++ b/test/validator/dependency_override_test.dart @@ -44,7 +44,7 @@ void main() { ]).create(); await expectValidationHint( - contains('Non-dev dependencies are overridden in pubspec.yaml.'), + 'Non-dev dependencies are overridden in pubspec.yaml.', ); }); test('it has a pubspec_overrides.yaml', () async { diff --git a/test/validator/dependency_test.dart b/test/validator/dependency_test.dart index ac7058384..2f34afc50 100644 --- a/test/validator/dependency_test.dart +++ b/test/validator/dependency_test.dart @@ -15,7 +15,7 @@ import '../test_pub.dart'; d.DirectoryDescriptor package({ String version = '1.0.0', - Map? deps, + Map? deps, String? sdk, }) { return d.dir(appPath, [ @@ -33,7 +33,7 @@ d.DirectoryDescriptor package({ } Future expectValidation({ - error, + Object? error, int exitCode = 0, Map environment = const {}, }) async { @@ -47,7 +47,7 @@ Future expectValidation({ } Future expectValidationWarning( - error, { + Object? error, { int count = 1, Map environment = const {}, }) async { @@ -74,7 +74,7 @@ Future expectValidationError( } Future setUpDependency( - dep, { + Map dep, { String? sdk, List hostedVersions = const [], }) async { @@ -160,7 +160,7 @@ void main() { test( 'depends on a package from Fuchsia with an appropriate Dart SDK constraint', () async { - await fuschiaPackage('foo', sdk: '^3.0.0').create(); + await fuchsiaPackage('foo', sdk: '^3.0.0').create(); await package( deps: { 'foo': {'sdk': 'fuchsia', 'version': '>=1.2.3 <2.0.0'}, @@ -403,7 +403,7 @@ void main() { }); } -d.Descriptor fuschiaPackage( +d.Descriptor fuchsiaPackage( String name, { Map deps = const {}, String? sdk, diff --git a/test/validator/file_case_test.dart b/test/validator/file_case_test.dart index 47da241aa..b2c0464d5 100644 --- a/test/validator/file_case_test.dart +++ b/test/validator/file_case_test.dart @@ -14,7 +14,7 @@ import 'package:test/test.dart'; import '../descriptor.dart' as d; import '../test_pub.dart'; -Future expectValidation(error, int exitCode) async { +Future expectValidation(Matcher error, int exitCode) async { await runPub( error: error, args: ['publish', '--dry-run'], diff --git a/test/validator/flutter_constraint_test.dart b/test/validator/flutter_constraint_test.dart index 42ddbf4d6..60800a209 100644 --- a/test/validator/flutter_constraint_test.dart +++ b/test/validator/flutter_constraint_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; import '../descriptor.dart' as d; import '../test_pub.dart'; -Future expectValidation(error, int exitCode) async { +Future expectValidation(Matcher error, int exitCode) async { await runPub( error: error, args: ['publish', '--dry-run'], diff --git a/test/validator/gitignore_test.dart b/test/validator/gitignore_test.dart index cf3e4d530..eabbca005 100644 --- a/test/validator/gitignore_test.dart +++ b/test/validator/gitignore_test.dart @@ -12,7 +12,7 @@ import '../descriptor.dart' as d; import '../test_pub.dart'; Future expectValidation( - error, + Matcher error, int exitCode, { Map environment = const {}, String? workingDirectory, diff --git a/test/validator/utils.dart b/test/validator/utils.dart index 430438292..3b3016cf4 100644 --- a/test/validator/utils.dart +++ b/test/validator/utils.dart @@ -13,9 +13,9 @@ import '../test_pub.dart'; // Prefer using expectValidation. Future expectValidationDeprecated( ValidatorCreator fn, { - hints, - warnings, - errors, + Object? hints, + Object? warnings, + Object? errors, int? size, }) async { final validator = await validatePackage(fn, size); @@ -25,7 +25,7 @@ Future expectValidationDeprecated( } Future expectValidation({ - error, + Object? error, int exitCode = 0, Map environment = const {}, List? extraArgs, @@ -42,28 +42,32 @@ Future expectValidation({ } Future expectValidationWarning( - error, { + String error, { int count = 1, Map environment = const {}, }) async { - if (error is String) error = contains(error); final s = count == 1 ? '' : 's'; await expectValidation( - error: allOf([error, contains('Package has $count warning$s')]), + error: allOf([ + contains(error), + contains('Package has $count warning$s'), + ]), exitCode: DATA, environment: environment, ); } Future expectValidationHint( - hint, { + String hint, { int count = 1, Map environment = const {}, }) async { - if (hint is String) hint = contains(hint); final s = count == 1 ? '' : 's'; await expectValidation( - error: allOf([hint, contains('and $count hint$s')]), + error: allOf([ + contains(hint), + contains('and $count hint$s'), + ]), environment: environment, ); } diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart index 3ae4f28b5..2712ad40a 100644 --- a/test/version_solver_test.dart +++ b/test/version_solver_test.dart @@ -1956,8 +1956,8 @@ void downgrade() { /// If [downgrade] is `true`, this runs "pub downgrade" instead of "pub get". Future expectResolves({ Map? result, - error, - output, + Object? error, + Object? output, int? tries, Map? environment, bool downgrade = false,