From e1fbda73d1ac597474b82882ee0bf6ecea5df108 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 29 Apr 2024 13:10:19 +0200 Subject: [PATCH] Use lint prefer_final_locals (#4247) --- analysis_options.yaml | 1 + lib/src/ascii_tree.dart | 8 +- lib/src/authentication/token_store.dart | 2 +- lib/src/command.dart | 8 +- lib/src/command/add.dart | 4 +- lib/src/command/cache_add.dart | 10 +- lib/src/command/cache_list.dart | 6 +- lib/src/command/cache_repair.dart | 12 +- lib/src/command/dependency_services.dart | 4 +- lib/src/command/deps.dart | 32 +++--- lib/src/command/downgrade.dart | 2 +- lib/src/command/get.dart | 2 +- lib/src/command/global_activate.dart | 12 +- lib/src/command/global_deactivate.dart | 4 +- lib/src/command/global_run.dart | 4 +- lib/src/command/lish.dart | 16 +-- lib/src/command/outdated.dart | 12 +- lib/src/command/remove.dart | 2 +- lib/src/command/run.dart | 6 +- lib/src/command/token_add.dart | 4 +- lib/src/command_runner.dart | 8 +- lib/src/dart.dart | 6 +- lib/src/entrypoint.dart | 8 +- lib/src/error_group.dart | 4 +- lib/src/executable.dart | 6 +- lib/src/git.dart | 2 +- lib/src/global_packages.dart | 90 +++++++-------- lib/src/http.dart | 18 +-- lib/src/io.dart | 55 ++++----- lib/src/isolate.dart | 4 +- lib/src/lock_file.dart | 12 +- lib/src/log.dart | 20 ++-- lib/src/oauth2.dart | 108 +++++++++--------- lib/src/package.dart | 8 +- lib/src/package_graph.dart | 4 +- lib/src/package_name.dart | 10 +- lib/src/progress.dart | 4 +- lib/src/pubspec.dart | 27 +++-- lib/src/pubspec_parse.dart | 8 +- lib/src/sdk/dart.dart | 16 +-- lib/src/sdk/flutter.dart | 4 +- lib/src/sdk/fuchsia.dart | 2 +- lib/src/solver/failure.dart | 56 ++++----- lib/src/solver/incompatibility.dart | 85 +++++++------- lib/src/solver/package_lister.dart | 48 ++++---- lib/src/solver/partial_solution.dart | 22 ++-- lib/src/solver/reformat_ranges.dart | 28 ++--- lib/src/solver/report.dart | 20 ++-- lib/src/solver/result.dart | 6 +- lib/src/solver/term.dart | 6 +- lib/src/solver/version_solver.dart | 36 +++--- lib/src/source/cached.dart | 2 +- lib/src/source/git.dart | 34 +++--- lib/src/source/hosted.dart | 39 ++++--- lib/src/source/path.dart | 10 +- lib/src/source/sdk.dart | 14 +-- lib/src/system_cache.dart | 4 +- lib/src/utils.dart | 48 ++++---- lib/src/validator.dart | 4 +- lib/src/validator/changelog.dart | 2 +- lib/src/validator/compiled_dartdoc.dart | 4 +- lib/src/validator/dependency.dart | 14 +-- lib/src/validator/dependency_override.dart | 4 +- lib/src/validator/directory.dart | 2 +- lib/src/validator/executable.dart | 2 +- lib/src/validator/gitignore.dart | 2 +- lib/src/validator/name.dart | 8 +- lib/src/validator/pubspec_field.dart | 6 +- lib/src/validator/readme.dart | 2 +- lib/src/validator/size.dart | 6 +- lib/src/validator/strict_dependencies.dart | 10 +- test/ascii_tree_test.dart | 4 +- test/cache/repair/git_test.dart | 28 ++--- test/cache/repair/handles_failure_test.dart | 2 +- .../repair/recompiles_snapshots_test.dart | 2 +- test/dependency_override_test.dart | 2 +- test/descriptor.dart | 8 +- test/descriptor/git.dart | 4 +- test/descriptor/tar.dart | 6 +- test/descriptor/yaml.dart | 4 +- .../doesnt_change_git_dependencies_test.dart | 2 +- test/embedding/ensure_pubspec_resolved.dart | 6 +- test/error_group_test.dart | 8 +- test/get/git/check_out_and_upgrade_test.dart | 2 +- test/get/git/check_out_branch_test.dart | 2 +- test/get/git/check_out_revision_test.dart | 4 +- ...nfetched_revision_of_cached_repo_test.dart | 4 +- .../clean_invalid_git_repo_cache_test.dart | 6 +- .../doesnt_fetch_if_nothing_changes_test.dart | 2 +- test/get/git/lock_version_test.dart | 2 +- .../locked_revision_without_repo_test.dart | 2 +- test/get/git/path_test.dart | 14 +-- .../git/stay_locked_if_compatible_test.dart | 2 +- test/get/git/unlock_if_incompatible_test.dart | 2 +- test/get/hosted/get_test.dart | 8 +- test/get/path/absolute_symlink_test.dart | 2 +- test/get/path/no_pubspec_test.dart | 2 +- test/get/path/nonexistent_dir_test.dart | 2 +- test/get/path/path_is_file_test.dart | 2 +- test/get/path/relative_path_test.dart | 6 +- .../activate_git_after_hosted_test.dart | 2 +- .../activate_hosted_after_git_test.dart | 2 +- .../activate_hosted_after_path_test.dart | 4 +- .../activate/activate_hosted_twice_test.dart | 4 +- .../activate_path_after_hosted_test.dart | 4 +- .../installs_dependencies_for_path_test.dart | 3 +- test/global/activate/path_package_test.dart | 4 +- .../binstub_runs_executable_test.dart | 4 +- .../does_not_warn_if_on_path_test.dart | 6 +- test/global/binstubs/missing_script_test.dart | 3 +- test/global/binstubs/name_collision_test.dart | 3 +- .../name_collision_with_overwrite_test.dart | 2 +- ...outdated_binstub_runs_pub_global_test.dart | 2 +- .../binstubs/outdated_snapshot_test.dart | 2 +- ...uns_once_even_when_dart_is_batch_test.dart | 2 +- .../unknown_explicit_executable_test.dart | 2 +- test/global/binstubs/utils.dart | 10 +- test/global/deactivate/path_package_test.dart | 2 +- test/global/list_test.dart | 2 +- .../run/implicit_executable_name_test.dart | 2 +- .../global/run/missing_path_package_test.dart | 2 +- test/global/run/nonexistent_script_test.dart | 2 +- test/global/run/package_api_test.dart | 16 +-- ...piles_if_snapshot_is_out_of_date_test.dart | 2 +- ...eflects_changes_to_local_package_test.dart | 2 +- test/global/run/runs_git_script_test.dart | 2 +- test/global/run/runs_path_script_test.dart | 2 +- .../run/runs_script_in_checked_mode_test.dart | 2 +- .../runs_script_in_unchecked_mode_test.dart | 2 +- test/global/run/runs_script_test.dart | 2 +- test/hosted/metadata_test.dart | 2 +- test/hosted/version_negotiation_test.dart | 2 +- test/ignore_test.dart | 4 +- test/io_test.dart | 78 ++++++------- .../archives_and_uploads_a_package_test.dart | 10 +- ...d_storage_upload_doesnt_redirect_test.dart | 2 +- ...storage_upload_provides_an_error_test.dart | 2 +- test/lish/does_not_include_dot_file.dart | 2 +- ...es_not_include_pubspec_overrides_file.dart | 2 +- ...package_validation_has_a_warning_test.dart | 4 +- ...ckage_validation_has_no_warnings_test.dart | 2 +- ..._not_publish_if_there_are_errors_test.dart | 2 +- ..._tests_are_no_warnings_or_errors_test.dart | 2 +- ..._publishes_if_there_are_warnings_test.dart | 4 +- test/lish/many_files_test.dart | 16 +-- ...ation_provides_a_malformed_error_test.dart | 4 +- ...ion_provides_a_malformed_success_test.dart | 4 +- ...ckage_creation_provides_an_error_test.dart | 2 +- ...e_creation_provides_invalid_json_test.dart | 2 +- ...tion_has_a_warning_and_continues_test.dart | 2 +- ...on_has_a_warning_and_is_canceled_test.dart | 4 +- .../package_validation_has_an_error_test.dart | 2 +- ...ver_arg_overrides_publish_to_url_test.dart | 2 +- test/lish/skip_validation_test.dart | 2 +- test/lish/unicode_file_names_test.dart | 2 +- ...rm_fields_has_a_non_string_value_test.dart | 4 +- .../upload_form_fields_is_not_a_map_test.dart | 4 +- .../upload_form_is_missing_fields_test.dart | 4 +- .../lish/upload_form_is_missing_url_test.dart | 4 +- .../upload_form_provides_an_error_test.dart | 2 +- ...pload_form_provides_invalid_json_test.dart | 2 +- .../upload_form_url_is_not_a_string_test.dart | 4 +- test/lish/uses_publish_to_url_test.dart | 2 +- test/lock_file_test.dart | 22 ++-- test/oauth2/utils.dart | 12 +- ..._credentials_authenticates_again_test.dart | 2 +- ...redentials_does_not_authenticate_test.dart | 2 +- ...efresh_token_authenticates_again_test.dart | 4 +- ..._credentials_refreshes_and_saves_test.dart | 2 +- ...efresh_token_authenticates_again_test.dart | 2 +- ...henticates_and_saves_credentials_test.dart | 2 +- ..._credentials_authenticates_again_test.dart | 2 +- test/package_config_file_test.dart | 2 +- test/package_server.dart | 4 +- test/pubspec_test.dart | 84 +++++++------- test/remove/remove_test.dart | 2 +- test/run/allows_dart_extension_test.dart | 2 +- test/run/app_can_read_from_stdin_test.dart | 4 +- ...rs_if_only_transitive_dependency_test.dart | 2 +- test/run/forwards_signal_posix_test.dart | 2 +- ...parent_directories_of_entrypoint_test.dart | 2 +- ..._package_imports_in_a_dependency_test.dart | 2 +- test/run/nonexistent_dependency_test.dart | 2 +- ...nonexistent_script_in_dependency_test.dart | 2 +- test/run/nonexistent_script_test.dart | 2 +- test/run/package_api_test.dart | 6 +- test/run/passes_along_arguments_test.dart | 3 +- test/run/precompile_test.dart | 10 +- test/run/runs_app_in_entrypoint_test.dart | 2 +- .../runs_named_app_in_dependency_test.dart | 2 +- ...runs_named_app_in_dev_dependency_test.dart | 2 +- ...runs_shorthand_app_in_dependency_test.dart | 2 +- test/snapshot_test.dart | 8 +- test/test_pub.dart | 60 +++++----- test/token/error_message_test.dart | 2 +- test/token/token_authentication_test.dart | 4 +- .../when_receives_401_removes_token_test.dart | 2 +- ...eceives_403_persists_saved_token_test.dart | 2 +- test/transcript_test.dart | 4 +- .../git/do_not_upgrade_if_unneeded_test.dart | 2 +- test/upgrade/git/upgrade_locked_test.dart | 4 +- test/upgrade/git/upgrade_one_locked_test.dart | 2 +- .../upgrade_to_incompatible_pubspec_test.dart | 2 +- .../upgrade_to_nonexistent_pubspec_test.dart | 4 +- test/utils_test.dart | 10 +- test/validator/directory_test.dart | 2 +- .../validator/flutter_plugin_format_test.dart | 22 ++-- test/validator/license_test.dart | 2 +- test/validator/pubspec_field_test.dart | 30 ++--- test/validator/pubspec_test.dart | 2 +- test/validator/readme_test.dart | 2 +- test/version_solver_test.dart | 18 +-- tool/extract_all_pub_dev.dart | 6 +- 213 files changed, 956 insertions(+), 947 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 8b82c826e..29602e060 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -33,6 +33,7 @@ linter: - package_api_docs - prefer_asserts_in_initializer_lists - prefer_const_declarations + - prefer_final_locals - prefer_relative_imports - prefer_single_quotes - require_trailing_commas diff --git a/lib/src/ascii_tree.dart b/lib/src/ascii_tree.dart index 58e93f429..fbd9c846c 100644 --- a/lib/src/ascii_tree.dart +++ b/lib/src/ascii_tree.dart @@ -66,7 +66,7 @@ String fromFiles( required bool showFileSizes, }) { // Parse out the files into a tree of nested maps. - var root = {}; + final root = {}; for (var file in files) { final relativeFile = baseDir == null ? file : p.relative(file, from: baseDir); @@ -117,7 +117,7 @@ String fromFiles( /// ' '---logging /// '---barback String fromMap(Map map, {bool startingAtTop = true}) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); _draw(buffer, '', null, map, depth: startingAtTop ? 0 : 1); return buffer.toString(); } @@ -162,10 +162,10 @@ void _draw( if (name != null) _drawLine(buffer, prefix, isLast, name, depth <= 1); // Recurse to the children. - var childNames = ordered(children.keys); + final childNames = ordered(children.keys); void drawChild(bool isLastChild, String child) { - var childPrefix = _getPrefix(depth <= 1, isLast); + final childPrefix = _getPrefix(depth <= 1, isLast); _draw( buffer, '$prefix$childPrefix', diff --git a/lib/src/authentication/token_store.dart b/lib/src/authentication/token_store.dart index a34fcd421..0f0cf4258 100644 --- a/lib/src/authentication/token_store.dart +++ b/lib/src/authentication/token_store.dart @@ -186,7 +186,7 @@ class TokenStore { /// /// `null` if no config directory could be found. String? get tokensFile { - var dir = configDir; + final dir = configDir; return dir == null ? null : p.join(dir, 'pub-tokens.json'); } } diff --git a/lib/src/command.dart b/lib/src/command.dart index 61f8cde80..3014a1c74 100644 --- a/lib/src/command.dart +++ b/lib/src/command.dart @@ -121,7 +121,7 @@ abstract class PubCommand extends Command { Command get _topCommand { Command current = this; while (true) { - var parent = current.parent; + final parent = current.parent; if (parent == null) return current; current = parent; } @@ -145,7 +145,7 @@ abstract class PubCommand extends Command { @override String get invocation { PubCommand? command = this; - var names = []; + final names = []; do { names.add(command?.name); command = command?.parent as PubCommand?; @@ -254,7 +254,7 @@ and attaching the relevant parts of that log file. /// appropriate exit code could be found. int _chooseExitCode(Object exception) { if (exception is SolveFailure) { - var packageNotFound = exception.packageNotFound; + final packageNotFound = exception.packageNotFound; if (packageNotFound != null) exception = packageNotFound; } while (exception is WrappedException && exception.innerError is Exception) { @@ -322,7 +322,7 @@ and attaching the relevant parts of that log file. } static void _computeCommand(ArgResults argResults) { - var list = []; + final list = []; for (var command = argResults.command; command != null; command = command.command) { diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index a3105150d..502294a11 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart @@ -300,8 +300,8 @@ Specify multiple sdk packages with descriptors.'''); ) async { final name = package.ref.name; final dependencies = [...original.dependencies.values]; - var devDependencies = [...original.devDependencies.values]; - var dependencyOverrides = [...original.dependencyOverrides.values]; + final devDependencies = [...original.devDependencies.values]; + final dependencyOverrides = [...original.dependencyOverrides.values]; final dependencyNames = dependencies.map((dependency) => dependency.name); final devDependencyNames = diff --git a/lib/src/command/cache_add.dart b/lib/src/command/cache_add.dart index cbcbda16e..693631f4f 100644 --- a/lib/src/command/cache_add.dart +++ b/lib/src/command/cache_add.dart @@ -42,12 +42,12 @@ class CacheAddCommand extends PubCommand { // Don't allow extra arguments. if (argResults.rest.length > 1) { - var unexpected = argResults.rest.skip(1).map((arg) => '"$arg"'); - var arguments = pluralize('argument', unexpected.length); + final unexpected = argResults.rest.skip(1).map((arg) => '"$arg"'); + final arguments = pluralize('argument', unexpected.length); usageException('Unexpected $arguments ${toSentence(unexpected)}.'); } - var package = argResults.rest.single; + final package = argResults.rest.single; // Parse the version constraint, if there is one. var constraint = VersionConstraint.any; @@ -61,10 +61,10 @@ class CacheAddCommand extends PubCommand { } // TODO(rnystrom): Support installing from git too. - var source = cache.hosted; + final source = cache.hosted; // TODO(rnystrom): Allow specifying the server. - var ids = (await cache.getVersions(source.refFor(package))) + final ids = (await cache.getVersions(source.refFor(package))) .where((id) => constraint.allows(id.version)) .toList(); diff --git a/lib/src/command/cache_list.dart b/lib/src/command/cache_list.dart index 76faaf089..ce3eb1b94 100644 --- a/lib/src/command/cache_list.dart +++ b/lib/src/command/cache_list.dart @@ -22,11 +22,11 @@ class CacheListCommand extends PubCommand { @override Future runProtected() async { // TODO(keertip): Add flag to list packages from non default sources. - var packagesObj = {}; + final packagesObj = {}; - var source = cache.defaultSource as CachedSource; + final source = cache.defaultSource as CachedSource; for (var package in source.getCachedPackages(cache)) { - var packageInfo = packagesObj.putIfAbsent(package.name, () => {}); + final packageInfo = packagesObj.putIfAbsent(package.name, () => {}); packageInfo[package.version.toString()] = {'location': package.dir}; } diff --git a/lib/src/command/cache_repair.dart b/lib/src/command/cache_repair.dart index 8e5892f0d..b61739457 100644 --- a/lib/src/command/cache_repair.dart +++ b/lib/src/command/cache_repair.dart @@ -37,15 +37,15 @@ class CacheRepairCommand extends PubCommand { final failures = repairResults.where((result) => !result.success); if (successes.isNotEmpty) { - var packages = pluralize('package', successes.length); + final packages = pluralize('package', successes.length); log.message( 'Reinstalled ${log.green(successes.length.toString())} $packages.', ); } if (failures.isNotEmpty) { - var packages = pluralize('package', failures.length); - var buffer = StringBuffer( + final packages = pluralize('package', failures.length); + final buffer = StringBuffer( 'Failed to reinstall ${log.red(failures.length.toString())} $packages:\n', ); @@ -60,17 +60,17 @@ class CacheRepairCommand extends PubCommand { log.message(buffer.toString()); } - var (repairSuccesses, repairFailures) = + final (repairSuccesses, repairFailures) = await globals.repairActivatedPackages(); if (repairSuccesses.isNotEmpty) { - var packages = pluralize('package', repairSuccesses.length); + final packages = pluralize('package', repairSuccesses.length); log.message( 'Reactivated ${log.green(repairSuccesses.length.toString())} $packages.', ); } if (repairFailures.isNotEmpty) { - var packages = pluralize('package', repairFailures.length); + final packages = pluralize('package', repairFailures.length); log.message( 'Failed to reactivate ${log.red(repairFailures.length.toString())} $packages:', ); diff --git a/lib/src/command/dependency_services.dart b/lib/src/command/dependency_services.dart index 9e1bcf7e2..63b81ccb7 100644 --- a/lib/src/command/dependency_services.dart +++ b/lib/src/command/dependency_services.dart @@ -374,9 +374,9 @@ class DependencyServicesApplyCommand extends PubCommand { ); // Remove the now outdated content-hash - it will be restored below // after resolution. - var packageMap = lockFileEditor + final packageMap = lockFileEditor .parseAt(['packages', targetPackage, 'description']).value as Map; - var hasSha = packageMap.containsKey('sha256'); + final hasSha = packageMap.containsKey('sha256'); if (hasSha) { lockFileEditor.remove( ['packages', targetPackage, 'description', 'sha256'], diff --git a/lib/src/command/deps.dart b/lib/src/command/deps.dart index 313d8a52f..45b3343d9 100644 --- a/lib/src/command/deps.dart +++ b/lib/src/command/deps.dart @@ -127,7 +127,7 @@ class DepsCommand extends PubCommand { }); toVisit.addAll(next); } - var executables = [ + final executables = [ for (final package in [ entrypoint.workspaceRoot, ...entrypoint.workspaceRoot.immediateDependencies.keys @@ -216,7 +216,7 @@ class DepsCommand extends PubCommand { ); } - var transitive = await _getTransitiveDependencies(); + final transitive = await _getTransitiveDependencies(); await _outputCompactPackages('transitive dependencies', transitive, buffer); } @@ -231,14 +231,14 @@ class DepsCommand extends PubCommand { buffer.writeln(); buffer.writeln('$section:'); for (var name in ordered(names)) { - var package = await _getPackage(name); + final package = await _getPackage(name); buffer.write('- ${_labelPackage(package)}'); if (package.dependencies.isEmpty) { buffer.writeln(); } else { - var depNames = package.dependencies.keys; - var depsList = "[${depNames.join(' ')}]"; + final depNames = package.dependencies.keys; + final depsList = "[${depNames.join(' ')}]"; buffer.writeln(' ${log.gray(depsList)}'); } } @@ -273,7 +273,7 @@ class DepsCommand extends PubCommand { ); } - var transitive = await _getTransitiveDependencies(); + final transitive = await _getTransitiveDependencies(); if (transitive.isEmpty) return; await _outputListSection( @@ -295,7 +295,7 @@ class DepsCommand extends PubCommand { buffer.writeln('$name:'); for (var name in deps) { - var package = await _getPackage(name); + final package = await _getPackage(name); buffer.writeln('- ${_labelPackage(package)}'); for (var dep in package.dependencies.values) { @@ -318,15 +318,15 @@ class DepsCommand extends PubCommand { // The work list for the breadth-first traversal. It contains the package // being added to the tree, and the parent map that will receive that // package. - var toWalk = Queue<(Package, Map)>(); - var visited = {}; + final toWalk = Queue<(Package, Map)>(); + final visited = {}; // Start with the root dependencies. - var packageTree = {}; + final packageTree = {}; final workspacePackageNames = [ ...entrypoint.workspaceRoot.transitiveWorkspace.map((p) => p.name), ]; - var immediateDependencies = + final immediateDependencies = entrypoint.workspaceRoot.immediateDependencies.keys.toSet(); if (!_includeDev) { immediateDependencies @@ -346,7 +346,7 @@ class DepsCommand extends PubCommand { } // Populate the map with this package's dependencies. - var childMap = {}; + final childMap = {}; map[_labelPackage(package)] = childMap; final isRoot = workspacePackageNames.contains(package.name); @@ -370,7 +370,7 @@ class DepsCommand extends PubCommand { /// Gets the names of the non-immediate dependencies of the workspace packages. Future> _getTransitiveDependencies() async { - var transitive = await _getAllDependencies(); + final transitive = await _getAllDependencies(); for (final root in entrypoint.workspaceRoot.transitiveWorkspace) { transitive.remove(root.name); transitive.removeAll(root.dependencies.keys); @@ -388,7 +388,7 @@ class DepsCommand extends PubCommand { return graph.packages.keys.toSet(); } - var nonDevDependencies = [ + final nonDevDependencies = [ for (final package in entrypoint.workspaceRoot.transitiveWorkspace) ...[ ...package.dependencies.keys, ...package.dependencyOverrides.keys, @@ -407,7 +407,7 @@ class DepsCommand extends PubCommand { /// but it's possible, since [Entrypoint.assertUpToDate]'s modification time /// check can return a false negative. This fails gracefully if that happens. Future _getPackage(String name) async { - var package = (await entrypoint.packageGraph).packages[name]; + final package = (await entrypoint.packageGraph).packages[name]; if (package != null) return package; dataError('The pubspec.yaml file has changed since the pubspec.lock file ' 'was generated, please run "$topLevelProgram pub get" again.'); @@ -426,7 +426,7 @@ class DepsCommand extends PubCommand { }; for (var package in packages) { - var executables = package.executableNames; + final executables = package.executableNames; if (executables.isNotEmpty) { buffer.writeln(_formatExecutables(package.name, executables.toList())); } diff --git a/lib/src/command/downgrade.dart b/lib/src/command/downgrade.dart index acd40c812..ae724dc98 100644 --- a/lib/src/command/downgrade.dart +++ b/lib/src/command/downgrade.dart @@ -81,7 +81,7 @@ class DowngradeCommand extends PubCommand { unlock: argResults.rest, dryRun: _dryRun, ); - var example = entrypoint.example; + final example = entrypoint.example; if (argResults.flag('example') && example != null) { await example.acquireDependencies( SolveType.get, diff --git a/lib/src/command/get.dart b/lib/src/command/get.dart index c795ec740..ce9ea76e7 100644 --- a/lib/src/command/get.dart +++ b/lib/src/command/get.dart @@ -80,7 +80,7 @@ class GetCommand extends PubCommand { enforceLockfile: argResults.flag('enforce-lockfile'), ); - var example = entrypoint.example; + final example = entrypoint.example; if ((argResults.flag('example')) && example != null) { await example.acquireDependencies( SolveType.get, diff --git a/lib/src/command/global_activate.dart b/lib/src/command/global_activate.dart index 47d290a78..3a2f0f957 100644 --- a/lib/src/command/global_activate.dart +++ b/lib/src/command/global_activate.dart @@ -99,15 +99,15 @@ class GlobalActivateCommand extends PubCommand { String readArg([String error = '']) { if (args.isEmpty) usageException(error); - var arg = args.first; + final arg = args.first; args = args.skip(1); return arg; } void validateNoExtraArgs() { if (args.isEmpty) return; - var unexpected = args.map((arg) => '"$arg"'); - var arguments = pluralize('argument', unexpected.length); + final unexpected = args.map((arg) => '"$arg"'); + final arguments = pluralize('argument', unexpected.length); usageException('Unexpected $arguments ${toSentence(unexpected)}.'); } @@ -121,7 +121,7 @@ class GlobalActivateCommand extends PubCommand { switch (argResults.optionWithDefault('source')) { case 'git': - var repo = readArg('No Git repository given.'); + final repo = readArg('No Git repository given.'); validateNoExtraArgs(); return globals.activateGit( repo, @@ -132,7 +132,7 @@ class GlobalActivateCommand extends PubCommand { ); case 'hosted': - var package = readArg('No package to activate given.'); + final package = readArg('No package to activate given.'); PackageRef ref; try { @@ -168,7 +168,7 @@ class GlobalActivateCommand extends PubCommand { ); case 'path': - var path = readArg('No package to activate given.'); + final path = readArg('No package to activate given.'); validateNoExtraArgs(); return globals.activatePath( path, diff --git a/lib/src/command/global_deactivate.dart b/lib/src/command/global_deactivate.dart index 7e99e1998..1e2ecc14c 100644 --- a/lib/src/command/global_deactivate.dart +++ b/lib/src/command/global_deactivate.dart @@ -24,8 +24,8 @@ class GlobalDeactivateCommand extends PubCommand { // Don't allow extra arguments. if (argResults.rest.length > 1) { - var unexpected = argResults.rest.skip(1).map((arg) => '"$arg"'); - var arguments = pluralize('argument', unexpected.length); + final unexpected = argResults.rest.skip(1).map((arg) => '"$arg"'); + final arguments = pluralize('argument', unexpected.length); usageException('Unexpected $arguments ${toSentence(unexpected)}.'); } diff --git a/lib/src/command/global_run.dart b/lib/src/command/global_run.dart index c6e996f41..31a209f8e 100644 --- a/lib/src/command/global_run.dart +++ b/lib/src/command/global_run.dart @@ -54,7 +54,7 @@ class GlobalRunCommand extends PubCommand { String package; var executable = argResults.rest[0]; if (executable.contains(':')) { - var parts = split1(executable, ':'); + final parts = split1(executable, ':'); package = parts[0]; executable = parts[1]; } else { @@ -62,7 +62,7 @@ class GlobalRunCommand extends PubCommand { package = executable; } - var args = argResults.rest.skip(1).toList(); + final args = argResults.rest.skip(1).toList(); if (p.split(executable).length > 1) { usageException('Cannot run an executable in a subdirectory of a global ' 'package.'); diff --git a/lib/src/command/lish.dart b/lib/src/command/lish.dart index af4a042e1..d24d09e8b 100644 --- a/lib/src/command/lish.dart +++ b/lib/src/command/lish.dart @@ -145,16 +145,16 @@ class LishCommand extends PubCommand { final parameters = parseJsonResponse(parametersResponse); /// 2. Upload package - var url = _expectField(parameters, 'url', parametersResponse); + final url = _expectField(parameters, 'url', parametersResponse); if (url is! String) invalidServerResponse(parametersResponse); cloudStorageUrl = Uri.parse(url); final uploadResponse = await retryForHttp('uploading package', () async { // TODO(nweiz): Cloud Storage can provide an XML-formatted error. We // should report that error and exit. - var request = http.MultipartRequest('POST', cloudStorageUrl!); + final request = http.MultipartRequest('POST', cloudStorageUrl!); - var fields = _expectField(parameters, 'fields', parametersResponse); + final fields = _expectField(parameters, 'fields', parametersResponse); if (fields is! Map) invalidServerResponse(parametersResponse); fields.forEach((key, value) { if (value is! String) invalidServerResponse(parametersResponse); @@ -173,7 +173,7 @@ class LishCommand extends PubCommand { }); /// 3. Finalize publish - var location = uploadResponse.headers['location']; + final location = uploadResponse.headers['location']; if (location == null) throw PubHttpResponseException(uploadResponse); final finalizeResponse = await retryForHttp('finalizing publish', () async { @@ -201,7 +201,7 @@ class LishCommand extends PubCommand { } dataError(msg + log.red('Authentication failed!')); } on PubHttpResponseException catch (error) { - var url = error.response.request!.url; + final url = error.response.request!.url; if (url == cloudStorageUrl) { handleGCSError(error.response); fail(log.red('Failed to upload the package.')); @@ -250,7 +250,7 @@ class LishCommand extends PubCommand { }); } } on PubHttpResponseException catch (error) { - var url = error.response.request!.url; + final url = error.response.request!.url; if (Uri.parse(url.origin) == Uri.parse(host.origin)) { handleJsonError(error.response); } else { @@ -303,11 +303,11 @@ the \$PUB_HOSTED_URL environment variable.''', await entrypoint.acquireDependencies(SolveType.get); } - var files = entrypoint.workPackage.listFiles(); + final files = entrypoint.workPackage.listFiles(); log.fine('Archiving and publishing ${entrypoint.workPackage.name}.'); // Show the package contents so the user can verify they look OK. - var package = entrypoint.workPackage; + final package = entrypoint.workPackage; final host = computeHost(package.pubspec); log.message( 'Publishing ${package.name} ${package.version} to $host:\n' diff --git a/lib/src/command/outdated.dart b/lib/src/command/outdated.dart index 283cb7b5b..23cfeb7d8 100644 --- a/lib/src/command/outdated.dart +++ b/lib/src/command/outdated.dart @@ -622,7 +622,7 @@ Future _outputHuman( log.message(b.toString()); } - var upgradable = rows.where( + final upgradable = rows.where( (row) { final current = row.current; final upgradable = row.upgradable; @@ -636,7 +636,7 @@ Future _outputHuman( }, ).length; - var notAtResolvable = rows.where( + final notAtResolvable = rows.where( (row) { final current = row.current; final upgradable = row.upgradable; @@ -712,7 +712,7 @@ Future _outputHuman( .toList(); } - var advisoriesToDisplay = >{}; + final advisoriesToDisplay = >{}; for (final package in rows) { advisoriesToDisplay[package.name] = advisoriesWithAffectedVersions(package); } @@ -740,7 +740,7 @@ Future _outputHuman( 'See https://dart.dev/go/package-retraction', ); } - var displayedAdvisories = advisoriesToDisplay[package.name]!; + final displayedAdvisories = advisoriesToDisplay[package.name]!; if (displayedAdvisories.isNotEmpty) { final advisoriesText = displayedAdvisories.length > 1 ? 'security advisories' @@ -752,7 +752,7 @@ Future _outputHuman( log.message('\n'); for (final advisory in displayedAdvisories) { - var displayedVersions = advisory.affectedVersions.intersection( + final displayedVersions = advisory.affectedVersions.intersection( [ package.current, package.upgradable, @@ -1054,7 +1054,7 @@ class _MarkedVersionDetails implements _Details { Object? toJson() { if (_versionDetails == null) return null; - var jsonExplanation = _jsonExplanation; + final jsonExplanation = _jsonExplanation; return jsonExplanation == null ? _versionDetails.toJson() : (_versionDetails.toJson()..addEntries([jsonExplanation])); diff --git a/lib/src/command/remove.dart b/lib/src/command/remove.dart index 0b1c2c699..5c2f84c24 100644 --- a/lib/src/command/remove.dart +++ b/lib/src/command/remove.dart @@ -96,7 +96,7 @@ To remove a dependency override of a package prefix the package name with dryRun: isDryRun, ); - var example = entrypoint.example; + final example = entrypoint.example; if (!isDryRun && argResults.flag('example') && example != null) { await example.acquireDependencies( SolveType.get, diff --git a/lib/src/command/run.dart b/lib/src/command/run.dart index c949551dd..a13597ed0 100644 --- a/lib/src/command/run.dart +++ b/lib/src/command/run.dart @@ -71,12 +71,12 @@ class RunCommand extends PubCommand { var package = entrypoint.workspaceRoot.name; var executable = argResults.rest[0]; - var args = argResults.rest.skip(1).toList(); + final args = argResults.rest.skip(1).toList(); // A command like "foo:bar" runs the "bar" script from the "foo" package. // If there is no colon prefix, default to the root package. if (executable.contains(':')) { - var components = split1(executable, ':'); + final components = split1(executable, ':'); package = components[0]; executable = components[1]; @@ -97,7 +97,7 @@ class RunCommand extends PubCommand { final vmArgs = vmArgsFromArgResults(argResults); - var exitCode = await runExecutable( + final exitCode = await runExecutable( entrypoint, Executable.adaptProgramName(package, executable), args, diff --git a/lib/src/command/token_add.dart b/lib/src/command/token_add.dart index a194cbcd0..c5336331b 100644 --- a/lib/src/command/token_add.dart +++ b/lib/src/command/token_add.dart @@ -60,8 +60,8 @@ For interactive authorization against pub.dev, use `$topLevelProgram pub login`. final rawHostedUrl = argResults.rest.first; try { - var hostedUrl = validateAndNormalizeHostedUrl(rawHostedUrl); - var isLocalhost = + final hostedUrl = validateAndNormalizeHostedUrl(rawHostedUrl); + final isLocalhost = ['localhost', '127.0.0.1', '::1'].contains(hostedUrl.host); if (!hostedUrl.isScheme('HTTPS') && !isLocalhost) { throw FormatException('url must be https://, ' diff --git a/lib/src/command_runner.dart b/lib/src/command_runner.dart index ee10f749f..03c724bfa 100644 --- a/lib/src/command_runner.dart +++ b/lib/src/command_runner.dart @@ -193,11 +193,11 @@ class PubCommandRunner extends CommandRunner implements PubTopLevel { if (!runningFromDartRepo) return; if (!git.isInstalled) return; - var deps = readTextFile(p.join(dartRepoRoot, 'DEPS')); - var pubRevRegExp = RegExp(r'^ +"pub_rev": +"@([^"]+)"', multiLine: true); - var match = pubRevRegExp.firstMatch(deps); + final deps = readTextFile(p.join(dartRepoRoot, 'DEPS')); + final pubRevRegExp = RegExp(r'^ +"pub_rev": +"@([^"]+)"', multiLine: true); + final match = pubRevRegExp.firstMatch(deps); if (match == null) return; - var depsRev = match[1]; + final depsRev = match[1]; String actualRev; final pubRoot = p.dirname(p.dirname(p.fromUri(Platform.script))); diff --git a/lib/src/dart.dart b/lib/src/dart.dart index 85e309559..56e69f5fe 100644 --- a/lib/src/dart.dart +++ b/lib/src/dart.dart @@ -54,7 +54,7 @@ class AnalysisContextManager { /// Throws [AnalyzerErrorGroup] is the file has parsing errors. CompilationUnit parse(String path) { path = p.normalize(p.absolute(path)); - var parseResult = _session.getParsedUnit(path); + final parseResult = _session.getParsedUnit(path); if (parseResult is ParsedUnitResult) { if (parseResult.errors.isNotEmpty) { throw AnalyzerErrorGroup(parseResult.errors); @@ -69,8 +69,8 @@ class AnalysisContextManager { /// /// Throws [AnalyzerErrorGroup] is the file has parsing errors. List parseImportsAndExports(String path) { - var unit = parse(path); - var uriDirectives = []; + final unit = parse(path); + final uriDirectives = []; for (var directive in unit.directives) { if (directive is UriBasedDirective) { uriDirectives.add(directive); diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index 557c2b0ee..e4507cee9 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart @@ -279,7 +279,7 @@ See $workspacesDocUrl for more information.''', // return the package-graph, such it by construction will always made from an // up-to-date package-config. await ensureUpToDate(workspaceRoot.dir, cache: cache); - var packages = { + final packages = { for (var packageEntry in packageConfig.nonInjectedPackages) packageEntry.name: Package.load( packageEntry.resolvedRootDir(packageConfigPath), @@ -760,7 +760,7 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without bool isDependencyUpToDate(PackageRange dep) { if (dep.name == root.name) return true; - var locked = lockFile.packages[dep.name]; + final locked = lockFile.packages[dep.name]; return locked != null && dep.allows(locked); } @@ -795,7 +795,7 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without return false; } - var overrides = MapKeySet(root.dependencyOverrides); + final overrides = MapKeySet(root.dependencyOverrides); // Check that uncached dependencies' pubspecs are also still satisfied, // since they're mutable and may have changed since the last get. @@ -1139,7 +1139,7 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without ); } return entrypoint.packageConfig; - case PackageConfig packageConfig: + case final PackageConfig packageConfig: log.fine('Package Config up to date.'); return packageConfig; } diff --git a/lib/src/error_group.dart b/lib/src/error_group.dart index 27a065f6c..88ef85d4c 100644 --- a/lib/src/error_group.dart +++ b/lib/src/error_group.dart @@ -71,7 +71,7 @@ class ErrorGroup { 'ErrorGroup.'); } - var wrapped = _ErrorGroupFuture(this, future); + final wrapped = _ErrorGroupFuture(this, future); _futures.add(wrapped); return wrapped; } @@ -94,7 +94,7 @@ class ErrorGroup { 'ErrorGroup.'); } - var wrapped = _ErrorGroupStream(this, stream); + final wrapped = _ErrorGroupStream(this, stream); _streams.add(wrapped); return wrapped; } diff --git a/lib/src/executable.dart b/lib/src/executable.dart index feaf10c04..1fb718058 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -67,7 +67,7 @@ Future runExecutable( } } - var snapshotPath = entrypoint.pathOfSnapshot(executable); + final snapshotPath = entrypoint.pathOfSnapshot(executable); // Don't compile snapshots for mutable packages, since their code may // change later on. @@ -75,7 +75,7 @@ Future runExecutable( // Also we don't snapshot if we have non-default arguments to the VM, as // these would be inconsistent if another set of settings are given in a // later invocation. - var useSnapshot = vmArgs.isEmpty; + final useSnapshot = vmArgs.isEmpty; var executablePath = executable.resolve( entrypoint.packageConfig, @@ -167,7 +167,7 @@ Future _runDartProgram( // We use Isolate.spawnUri when there are no extra vm-options. // That provides better signal handling, and possibly faster startup. if ((!alwaysUseSubprocess) && vmArgs.isEmpty) { - var argList = args.toList(); + final argList = args.toList(); return await isolate.runUri( p.toUri(path), argList, diff --git a/lib/src/git.dart b/lib/src/git.dart index c091a4f19..10870341b 100644 --- a/lib/src/git.dart +++ b/lib/src/git.dart @@ -146,7 +146,7 @@ final _minSupportedGitVersion = Version(2, 14, 0); bool _tryGitCommand(String command) { // If "git --version" prints something familiar, git is working. try { - var result = runProcessSync(command, ['--version']); + final result = runProcessSync(command, ['--version']); final output = result.stdout; // Some users may have configured commands such as autorun, which may diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index 9ce849c5a..cc8990353 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -93,7 +93,7 @@ class GlobalPackages { String? path, String? ref, }) async { - var name = await cache.git.getPackageNameFromRepo( + final name = await cache.git.getPackageNameFromRepo( repo, ref, path, @@ -178,16 +178,16 @@ class GlobalPackages { List? executables, { required bool overwriteBinStubs, }) async { - var entrypoint = Entrypoint(path, cache); + final entrypoint = Entrypoint(path, cache); // Get the package's dependencies. await entrypoint.acquireDependencies(SolveType.get); - var name = entrypoint.workspaceRoot.name; + final name = entrypoint.workspaceRoot.name; _describeActive(name, cache); // Write a lockfile that points to the local package. - var fullPath = canonicalize(entrypoint.workspaceRoot.dir); - var id = cache.path.idFor( + final fullPath = canonicalize(entrypoint.workspaceRoot.dir); + final id = cache.path.idFor( name, entrypoint.workspaceRoot.version, fullPath, @@ -226,7 +226,7 @@ class GlobalPackages { final tempDir = cache.createTempDir(); // Create a dummy package with just [dep] so we can do resolution on it. - var root = packageForConstraint(dep, tempDir); + final root = packageForConstraint(dep, tempDir); // Resolve it and download its dependencies. SolveResult result; @@ -320,7 +320,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam // Couldn't read the lock file. It probably doesn't exist. return null; } - var id = lockFile.packages[name]!; + final id = lockFile.packages[name]!; final description = id.description.description; if (description is GitDescription) { @@ -340,7 +340,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam /// /// Returns `false` if no package with [name] was currently active. bool deactivate(String name) { - var dir = p.join(_directory, name); + final dir = p.join(_directory, name); if (!dirExists(_directory)) { return false; } @@ -357,8 +357,8 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam _deleteBinStubs(name); - var lockFile = LockFile.load(_getLockFilePath(name), cache.sources); - var id = lockFile.packages[name]!; + final lockFile = LockFile.load(_getLockFilePath(name), cache.sources); + final id = lockFile.packages[name]!; log.message('Deactivated package ${_formatPackage(id)}.'); deleteEntry(dir); @@ -370,7 +370,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam /// /// Returns an [Entrypoint] loaded with the active package if found. Future find(String name) async { - var lockFilePath = _getLockFilePath(name); + final lockFilePath = _getLockFilePath(name); late final LockFile lockFile; try { lockFile = LockFile.load(lockFilePath, cache.sources); @@ -401,7 +401,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam // Check that the SDK constraints the lockFile says we have are honored. lockFile.sdkConstraints.forEach((sdkName, constraint) { - var sdk = sdks[sdkName]; + final sdk = sdks[sdkName]; if (sdk == null) { dataError('${log.bold(name)} as globally activated requires ' 'unknown SDK "$name".'); @@ -476,10 +476,10 @@ try: /// path to a single lockfile or a new-style path to a directory containing a /// lockfile. PackageId _loadPackageId(String path) { - var name = p.basenameWithoutExtension(path); + final name = p.basenameWithoutExtension(path); if (!fileExists(path)) path = p.join(path, 'pubspec.lock'); - var id = + final id = LockFile.load(p.join(_directory, path), cache.sources).packages[name]; if (id == null) { @@ -494,10 +494,10 @@ try: String _formatPackage(PackageId id) { final description = id.description.description; if (description is GitDescription) { - var url = GitDescription.prettyUri(description.url); + final url = GitDescription.prettyUri(description.url); return '${log.bold(id.name)} ${id.version} from Git repository "$url"'; } else if (description is PathDescription) { - var path = description.path; + final path = description.path; return '${log.bold(id.name)} ${id.version} at path "$path"'; } else { return '${log.bold(id.name)} ${id.version}'; @@ -510,17 +510,17 @@ try: /// were successfully re-activated; the second indicates which failed. Future<(List successes, List failures)> repairActivatedPackages() async { - var executables = >{}; + final executables = >{}; if (dirExists(_binStubDir)) { for (var entry in listDir(_binStubDir)) { try { - var binstub = readTextFile(entry); - var package = _binStubProperty(binstub, 'Package'); + final binstub = readTextFile(entry); + final package = _binStubProperty(binstub, 'Package'); if (package == null) { throw ApplicationException("No 'Package' property."); } - var executable = _binStubProperty(binstub, 'Executable'); + final executable = _binStubProperty(binstub, 'Executable'); if (executable == null) { throw ApplicationException("No 'Executable' property."); } @@ -539,8 +539,8 @@ try: } } - var successes = []; - var failures = []; + final successes = []; + final failures = []; if (dirExists(_directory)) { for (var entry in listDir(_directory)) { PackageId? id; @@ -548,7 +548,7 @@ try: id = _loadPackageId(entry); log.message('Reactivating ${log.bold(id.name)} ${id.version}...'); - var entrypoint = await find(id.name); + final entrypoint = await find(id.name); final packageExecutables = executables.remove(id.name) ?? []; if (entrypoint.isCached) { @@ -584,7 +584,7 @@ try: } if (executables.isNotEmpty) { - var message = StringBuffer('Binstubs exist for non-activated ' + final message = StringBuffer('Binstubs exist for non-activated ' 'packages:\n'); executables.forEach((package, executableNames) { for (var executable in executableNames) { @@ -607,9 +607,9 @@ try: void _refreshBinStubs(Entrypoint entrypoint, exec.Executable executable) { if (!dirExists(_binStubDir)) return; for (var file in listDir(_binStubDir, includeDirs: false)) { - var contents = readTextFile(file); - var binStubPackage = _binStubProperty(contents, 'Package'); - var binStubScript = _binStubProperty(contents, 'Script'); + final contents = readTextFile(file); + final binStubPackage = _binStubProperty(contents, 'Package'); + final binStubScript = _binStubProperty(contents, 'Script'); if (binStubPackage == null || binStubScript == null) { log.fine('Could not parse binstub $file:\n$contents'); continue; @@ -667,15 +667,15 @@ try: ensureDir(_binStubDir); - var installed = []; - var collided = {}; - var allExecutables = ordered(package.pubspec.executables.keys); + final installed = []; + final collided = {}; + final allExecutables = ordered(package.pubspec.executables.keys); for (var executable in allExecutables) { if (executables != null && !executables.contains(executable)) continue; - var script = package.pubspec.executables[executable]!; + final script = package.pubspec.executables[executable]!; - var previousPackage = _createBinStub( + final previousPackage = _createBinStub( package, executable, script, @@ -694,7 +694,7 @@ try: } if (installed.isNotEmpty) { - var names = namedSequence('executable', installed.map(log.bold)); + final names = namedSequence('executable', installed.map(log.bold)); log.message('Installed $names.'); } @@ -718,7 +718,7 @@ try: // Show errors for any unknown executables. if (executables != null) { - var unknown = ordered( + final unknown = ordered( executables .where((exe) => !package.pubspec.executables.keys.contains(exe)), ); @@ -730,10 +730,10 @@ try: // Show errors for any missing scripts. // TODO(rnystrom): This can print false positives since a script may be // produced by a transformer. Do something better. - var binFiles = package.executablePaths; + final binFiles = package.executablePaths; for (var executable in installed) { - var script = package.pubspec.executables[executable]; - var scriptPath = p.join('bin', '$script.dart'); + final script = package.pubspec.executables[executable]; + final scriptPath = p.join('bin', '$script.dart'); if (!binFiles.contains(scriptPath)) { log.warning('Warning: Executable "$executable" runs "$scriptPath", ' 'which was not found in ${log.bold(package.name)}.'); @@ -770,7 +770,7 @@ try: // since we already deleted all of this package's binstubs. String? previousPackage; if (fileExists(binStubPath)) { - var contents = readTextFile(binStubPath); + final contents = readTextFile(binStubPath); previousPackage = _binStubProperty(contents, 'Package'); if (previousPackage == null) { log.fine('Could not parse binstub $binStubPath:\n$contents'); @@ -854,7 +854,7 @@ fi if (Platform.isLinux || Platform.isMacOS) { // Make it executable. - var result = Process.runSync('chmod', ['+x', tmpPath]); + final result = Process.runSync('chmod', ['+x', tmpPath]); if (result.exitCode != 0) { // Couldn't make it executable so don't leave it laying around. fail('Could not make "$tmpPath" executable (exit code ' @@ -874,8 +874,8 @@ fi if (!dirExists(_binStubDir)) return; for (var file in listDir(_binStubDir, includeDirs: false)) { - var contents = readTextFile(file); - var binStubPackage = _binStubProperty(contents, 'Package'); + final contents = readTextFile(file); + final binStubPackage = _binStubProperty(contents, 'Package'); if (binStubPackage == null) { log.fine('Could not parse binstub $file:\n$contents'); continue; @@ -897,7 +897,7 @@ fi if (Platform.isWindows) { // See if the shell can find one of the binstubs. // "\q" means return exit code 0 if found or 1 if not. - var result = runProcessSync('where', [r'\q', '$installed.bat']); + final result = runProcessSync('where', [r'\q', '$installed.bat']); if (result.exitCode == 0) return; log.warning("${log.yellow('Warning:')} Pub installs executables into " @@ -910,7 +910,7 @@ fi // // The "command" builtin is more reliable than the "which" executable. See // http://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then - var result = + final result = runProcessSync('command', ['-v', installed], runInShell: true); if (result.exitCode == 0) return; @@ -938,8 +938,8 @@ fi /// Returns the value of the property named [name] in the bin stub script /// [source]. String? _binStubProperty(String source, String name) { - var pattern = RegExp(RegExp.escape(name) + r': ([a-zA-Z0-9_-]+)'); - var match = pattern.firstMatch(source); + final pattern = RegExp(RegExp.escape(name) + r': ([a-zA-Z0-9_-]+)'); + final match = pattern.firstMatch(source); return match == null ? null : match[1]; } } diff --git a/lib/src/http.dart b/lib/src/http.dart index 8ff7c771a..f281434ad 100644 --- a/lib/src/http.dart +++ b/lib/src/http.dart @@ -89,14 +89,14 @@ class _PubHttpClient extends http.BaseClient { /// Logs the fact that [request] was sent, and information about it. void _logRequest(http.BaseRequest request) { - var requestLog = StringBuffer(); + final requestLog = StringBuffer(); requestLog.writeln('HTTP ${request.method} ${request.url}'); request.headers .forEach((name, value) => requestLog.writeln(_logField(name, value))); if (request.method == 'POST') { - var contentTypeString = request.headers[HttpHeaders.contentTypeHeader]; - var contentType = ContentType.parse(contentTypeString ?? ''); + final contentTypeString = request.headers[HttpHeaders.contentTypeHeader]; + final contentType = ContentType.parse(contentTypeString ?? ''); if (request is http.MultipartRequest) { requestLog.writeln(); requestLog.writeln('Body fields:'); @@ -127,9 +127,9 @@ class _PubHttpClient extends http.BaseClient { // TODO(nweiz): Fork the response stream and log the response body. Be // careful not to log OAuth2 private data, though. - var responseLog = StringBuffer(); - var request = response.request!; - var stopwatch = _requestStopwatches.remove(request)!..stop(); + final responseLog = StringBuffer(); + final request = response.request!; + final stopwatch = _requestStopwatches.remove(request)!..stop(); responseLog.writeln('HTTP response ${response.statusCode} ' '${response.reasonPhrase} for ${request.method} ${request.url}'); responseLog.writeln('took ${stopwatch.elapsed}'); @@ -197,12 +197,12 @@ extension AttachHeaders on http.Request { headers['X-Pub-Command'] = PubCommand.command; headers['X-Pub-Session-ID'] = _sessionId; - var environment = Platform.environment['PUB_ENVIRONMENT']; + final environment = Platform.environment['PUB_ENVIRONMENT']; if (environment != null) { headers['X-Pub-Environment'] = environment; } - var type = Zone.current[#_dependencyType]; + final type = Zone.current[#_dependencyType]; if (type != null && type != DependencyType.none) { headers['X-Pub-Reason'] = type.toString(); } @@ -238,7 +238,7 @@ void handleJsonError(http.BaseResponse response) { // See https://github.com/dart-lang/pub/pull/3590#discussion_r1012978108 fail(log.red('Invalid server response')); } - var errorMap = parseJsonResponse(response); + final errorMap = parseJsonResponse(response); final error = errorMap['error']; if (error is! Map || !error.containsKey('message') || diff --git a/lib/src/io.dart b/lib/src/io.dart index fabafa3dd..ffaa5fd68 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -108,7 +108,7 @@ FileStat? tryStatFile(String path) { /// filesystem; nonexistent or unreadable path entries are treated as normal /// directories. String canonicalize(String pathString) { - var seen = {}; + final seen = {}; var components = Queue.from(p.split(p.normalize(p.absolute(pathString)))); @@ -120,15 +120,16 @@ String canonicalize(String pathString) { // resolved in turn. while (components.isNotEmpty) { seen.add(p.join(newPath, p.joinAll(components))); - var resolvedPath = _resolveLink(p.join(newPath, components.removeFirst())); - var relative = p.relative(resolvedPath, from: newPath); + final resolvedPath = + _resolveLink(p.join(newPath, components.removeFirst())); + final relative = p.relative(resolvedPath, from: newPath); // If the resolved path of the component relative to `newPath` is just ".", // that means component was a symlink pointing to its parent directory. We // can safely ignore such components. if (relative == '.') continue; - var relativeComponents = Queue.from(p.split(relative)); + final relativeComponents = Queue.from(p.split(relative)); // If the resolved path is absolute relative to `newPath`, that means it's // on a different drive. We need to canonicalize the entire target of that @@ -165,7 +166,7 @@ String canonicalize(String pathString) { // If we've already tried to canonicalize the new path, we've encountered a // symlink loop. Avoid going infinite by treating the recursive symlink as // the canonical path. - var newSubPath = p.join(newPath, p.joinAll(relativeComponents)); + final newSubPath = p.join(newPath, p.joinAll(relativeComponents)); if (seen.contains(newSubPath)) { newPath = newSubPath; continue; @@ -189,7 +190,7 @@ String canonicalize(String pathString) { /// /// This accepts paths to non-links or broken links, and returns them as-is. String _resolveLink(String link) { - var seen = {}; + final seen = {}; while (linkExists(link) && seen.add(link)) { link = p.normalize(p.join(p.dirname(link), Link(link).targetSync())); } @@ -207,7 +208,7 @@ Future readTextFileAsync(String file) { /// Reads the contents of the binary file [file]. Uint8List readBinaryFile(String file) { log.io('Reading binary file $file.'); - var contents = File(file).readAsBytesSync(); + final contents = File(file).readAsBytesSync(); log.io('Read ${contents.length} bytes from $file.'); return contents; } @@ -215,7 +216,7 @@ Uint8List readBinaryFile(String file) { /// Reads the contents of the binary file [file] as a [Stream]. Stream> readBinaryFileAsStream(String file) { log.io('Reading binary file $file.'); - var contents = File(file).openRead(); + final contents = File(file).openRead(); return contents; } @@ -308,7 +309,7 @@ String ensureDir(String dir) { /// /// Returns the path of the created directory. String createTempDir(String base, String prefix) { - var tempDir = Directory(base).createTempSync(prefix); + final tempDir = Directory(base).createTempSync(prefix); log.io('Created temp directory ${tempDir.path}'); return tempDir.path; } @@ -318,7 +319,7 @@ String createTempDir(String base, String prefix) { /// /// Returns the path of the created directory. Future _createSystemTempDir() async { - var tempDir = await Directory.systemTemp.createTemp('pub_'); + final tempDir = await Directory.systemTemp.createTemp('pub_'); log.io('Created temp directory ${tempDir.path}'); return tempDir.resolveSymbolicLinksSync(); } @@ -352,7 +353,7 @@ List listDir( bool includeDirs = true, Iterable allowed = const [], }) { - var allowListFilter = createFileFilter(allowed); + final allowListFilter = createFileFilter(allowed); // This is used in some performance-sensitive paths and can list many, many // files. As such, it leans more heavily towards optimization as opposed to @@ -448,7 +449,7 @@ void _attempt( operation(); break; } on FileSystemException catch (error) { - var reason = getErrorReason(error); + final reason = getErrorReason(error); if (reason == null) rethrow; if (i < maxRetries - 1) { @@ -579,7 +580,7 @@ void createSymlink(String target, String symlink, {bool relative = false}) { // If the directory where we're creating the symlink was itself reached // by traversing a symlink, we want the relative path to be relative to // it's actual location, not the one we went through to get to it. - var symlinkDir = canonicalize(p.dirname(symlink)); + final symlinkDir = canonicalize(p.dirname(symlink)); target = p.normalize(p.relative(target, from: symlinkDir)); } } @@ -658,7 +659,7 @@ final String dartRepoRoot = (() { // Get the URL of the repo root in a way that works when either both running // as a test or as a pub executable. - var url = Platform.script + final url = Platform.script .replace(path: Platform.script.path.replaceAll(_dartRepoRegExp, '')); return p.fromUri(url); })(); @@ -736,8 +737,8 @@ Future flushThenExit(int status) { (EventSink consumerSink, Future done) _consumerToSink( StreamConsumer consumer, ) { - var controller = StreamController(sync: true); - var done = controller.stream.pipe(consumer); + final controller = StreamController(sync: true); + final done = controller.stream.pipe(consumer); return (controller.sink, done); } @@ -780,7 +781,7 @@ Future runProcess( ); } - var pubResult = PubProcessResult( + final pubResult = PubProcessResult( result.stdout as String, result.stderr as String, result.exitCode, @@ -824,7 +825,7 @@ Future startProcess( ); } - var process = PubProcess(ioProcess); + final process = PubProcess(ioProcess); unawaited(process.exitCode.whenComplete(resource.release)); return process; }); @@ -857,7 +858,7 @@ PubProcessResult runProcessSync( } on IOException catch (e) { throw RunProcessException('Pub failed to run subprocess `$executable`: $e'); } - var pubResult = PubProcessResult( + final pubResult = PubProcessResult( result.stdout as String, result.stderr as String, result.exitCode, @@ -928,18 +929,18 @@ class PubProcess { /// Creates a new [PubProcess] wrapping [process]. PubProcess(Process process) : _process = process { - var errorGroup = ErrorGroup(); + final errorGroup = ErrorGroup(); - var (consumerSink, done) = _consumerToSink(process.stdin); + final (consumerSink, done) = _consumerToSink(process.stdin); _stdin = consumerSink; _stdinClosed = errorGroup.registerFuture(done); _stdout = ByteStream(errorGroup.registerStream(process.stdout)); _stderr = ByteStream(errorGroup.registerStream(process.stderr)); - var exitCodeCompleter = Completer(); + final exitCodeCompleter = Completer(); _exitCode = errorGroup.registerFuture(exitCodeCompleter.future); - _process.exitCode.then((code) => exitCodeCompleter.complete(code)); + _process.exitCode.then(exitCodeCompleter.complete); } /// Sends [signal] to the underlying process. @@ -982,7 +983,7 @@ void touch(String path) { /// Returns a future that completes to the value that the future returned from /// [fn] completes to. Future withTempDir(FutureOr Function(String path) fn) async { - var tempDir = await _createSystemTempDir(); + final tempDir = await _createSystemTempDir(); try { return await fn(tempDir); } finally { @@ -995,7 +996,7 @@ Future withTempDir(FutureOr Function(String path) fn) async { /// If [host] is "localhost", this will automatically listen on both the IPv4 /// and IPv6 loopback addresses. Future bindServer(String host, int port) async { - var server = host == 'localhost' + final server = host == 'localhost' ? await HttpMultiServer.loopback(port) : await HttpServer.bind(host, port); server.autoCompress = true; @@ -1136,7 +1137,7 @@ ByteStream createTarGz( List contents, { required String baseDir, }) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); buffer.write('Creating .tar.gz stream containing:\n'); contents.forEach(buffer.writeln); log.fine(buffer.toString()); @@ -1197,7 +1198,7 @@ class PubProcessResult { // TODO(rnystrom): Remove this and change to returning one string. static List _toLines(String output) { - var lines = splitLines(output); + final lines = splitLines(output); if (lines.isNotEmpty && lines.last == '') lines.removeLast(); return lines; } diff --git a/lib/src/isolate.dart b/lib/src/isolate.dart index 0958a6c5b..49217f4df 100644 --- a/lib/src/isolate.dart +++ b/lib/src/isolate.dart @@ -25,8 +25,8 @@ Future runUri( bool automaticPackageResolution = false, Uri? packageConfig, }) async { - var errorPort = ReceivePort(); - var exitPort = ReceivePort(); + final errorPort = ReceivePort(); + final exitPort = ReceivePort(); await Isolate.spawnUri( url, diff --git a/lib/src/lock_file.dart b/lib/src/lock_file.dart index 67172636a..d2a018706 100644 --- a/lib/src/lock_file.dart +++ b/lib/src/lock_file.dart @@ -170,15 +170,15 @@ class LockFile { // Parse the source. final sourceName = _getStringEntry(spec, 'source'); - var descriptionNode = + final descriptionNode = _getEntry(spec, 'description', 'description'); - dynamic description = descriptionNode is YamlScalar + final dynamic description = descriptionNode is YamlScalar ? descriptionNode.value : descriptionNode; // Let the source parse the description. - var source = sources(sourceName); + final source = sources(sourceName); PackageId id; try { id = source.parseId( @@ -337,7 +337,7 @@ class LockFile { LockFile removePackage(String name) { if (!this.packages.containsKey(name)) return this; - var packages = Map.from(this.packages); + final packages = Map.from(this.packages); packages.remove(name); return LockFile._( packages, @@ -355,7 +355,7 @@ class LockFile { /// serialized as absolute. String serialize(String? packageDir, SystemCache cache) { // Convert the dependencies to a simple object. - var packageMap = {}; + final packageMap = {}; for (final id in packages.values) { packageMap[id.name] = { 'version': id.version.toString(), @@ -366,7 +366,7 @@ class LockFile { }; } - var data = { + final data = { 'sdks': mapMap( sdkConstraints, value: (_, constraint) => constraint.effectiveConstraint.toString(), diff --git a/lib/src/log.dart b/lib/src/log.dart index a7fdd2bd8..94db39f77 100644 --- a/lib/src/log.dart +++ b/lib/src/log.dart @@ -233,7 +233,7 @@ void fine(String message) => write(Level.fine, message); /// Logs [message] at [level]. void write(Level level, String message) { message = message.toString(); - var lines = splitLines(message); + final lines = splitLines(message); // Discard a trailing newline. This is useful since StringBuffers often end // up with an extra newline at the end from using [writeln]. @@ -241,9 +241,9 @@ void write(Level level, String message) { lines.removeLast(); } - var entry = _Entry(level, lines); + final entry = _Entry(level, lines); - var logFn = verbosity._loggers[level]; + final logFn = verbosity._loggers[level]; if (logFn != null) logFn(entry); _transcript.add(entry); @@ -263,7 +263,7 @@ void process( /// Logs the results of running [executable]. void processResult(String executable, PubProcessResult result) { // Log it all as one message so that it shows up as a single unit in the logs. - var buffer = StringBuffer(); + final buffer = StringBuffer(); buffer.writeln('Finished $executable. Exit code ${result.exitCode}.'); void dumpOutput(String name, List output) { @@ -294,7 +294,7 @@ void processResult(String executable, PubProcessResult result) { void exception(Object exception, [StackTrace? trace]) { if (exception is SilentException) return; - var chain = trace == null ? Chain.current() : Chain.forTrace(trace); + final chain = trace == null ? Chain.current() : Chain.forTrace(trace); // This is basically the top-level exception handler so that we don't // spew a stack trace on our users. @@ -445,7 +445,7 @@ Future errorsOnlyUnlessTerminal(FutureOr Function() callback) async { Future progress(String message, Future Function() callback) { _stopProgress(); - var progress = Progress(message); + final progress = Progress(message); _animatedProgress = progress; return callback().whenComplete(progress.stop); } @@ -459,11 +459,9 @@ Future spinner( if (condition) { _stopProgress(); - var progress = Progress(message); + final progress = Progress(message); _animatedProgress = progress; - return callback().whenComplete(() { - progress.stopAndClear(); - }); + return callback().whenComplete(progress.stopAndClear); } return callback(); } @@ -614,7 +612,7 @@ class _JsonLogger { /// /// Always prints to stdout. void error(Object error, [StackTrace? stackTrace]) { - var errorJson = {'error': error.toString()}; + final errorJson = {'error': error.toString()}; if (stackTrace == null && error is Error) stackTrace = error.stackTrace; if (stackTrace != null) { diff --git a/lib/src/oauth2.dart b/lib/src/oauth2.dart index 1688646e9..9a116ef43 100644 --- a/lib/src/oauth2.dart +++ b/lib/src/oauth2.dart @@ -62,7 +62,7 @@ final _authorizationEndpoint = /// This can be controlled externally by setting the `_PUB_TEST_TOKEN_ENDPOINT` /// environment variable. Uri get tokenEndpoint { - var tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT']; + final tokenEndpoint = Platform.environment['_PUB_TEST_TOKEN_ENDPOINT']; if (tokenEndpoint != null) { return Uri.parse(tokenEndpoint); } else { @@ -87,7 +87,7 @@ Credentials? _credentials; /// Delete the cached credentials, if they exist. void _clearCredentials() { _credentials = null; - var credentialsFile = _credentialsFile(); + final credentialsFile = _credentialsFile(); if (credentialsFile != null && entryExists(credentialsFile)) { deleteEntry(credentialsFile); } @@ -95,7 +95,7 @@ void _clearCredentials() { /// Try to delete the cached credentials. void logout() { - var credentialsFile = _credentialsFile(); + final credentialsFile = _credentialsFile(); if (credentialsFile != null && entryExists(credentialsFile)) { log.message('Logging out of pub.dev.'); log.message('Deleting $credentialsFile'); @@ -149,10 +149,10 @@ Future withClient(Future Function(http.Client) fn) { /// If saved credentials are available, those are used; otherwise, the user is /// prompted to authorize the pub client. Future<_Client> _getClient() async { - var credentials = loadCredentials(); + final credentials = loadCredentials(); if (credentials == null) return await _authorize(); - var client = _Client( + final client = _Client( credentials, identifier: _identifier, secret: _secret, @@ -175,10 +175,10 @@ Credentials? loadCredentials() { try { if (_credentials != null) return _credentials; - var path = _credentialsFile(); + final path = _credentialsFile(); if (path == null || !fileExists(path)) return null; - var credentials = Credentials.fromJson(readTextFile(path)); + final credentials = Credentials.fromJson(readTextFile(path)); if (credentials.isExpired && !credentials.canRefresh) { log.error("Pub's authorization to upload packages has expired and " "can't be automatically refreshed."); @@ -200,7 +200,7 @@ Credentials? loadCredentials() { void _saveCredentials(Credentials credentials) { log.fine('Saving OAuth2 credentials.'); _credentials = credentials; - var credentialsPath = _credentialsFile(); + final credentialsPath = _credentialsFile(); if (credentialsPath != null) { ensureDir(p.dirname(credentialsPath)); writeTextFile(credentialsPath, credentials.toJson(), dontLogContents: true); @@ -219,7 +219,7 @@ String? _credentialsFile() { /// /// Returns a Future that completes to a fully-authorized [_Client]. Future<_Client> _authorize() async { - var grant = _AuthorizationCodeGrant( + final grant = _AuthorizationCodeGrant( _identifier, _authorizationEndpoint, tokenEndpoint, secret: _secret, // Google's OAuth2 API doesn't support basic auth. @@ -230,15 +230,15 @@ Future<_Client> _authorize() async { // Spin up a one-shot HTTP server to receive the authorization code from the // Google OAuth2 server via redirect. This server will close itself as soon as // the code is received. - var completer = Completer<_Client>(); - var server = await bindServer('localhost', 0); + final completer = Completer<_Client>(); + final server = await bindServer('localhost', 0); shelf_io.serveRequests(server, (request) { if (request.url.path.isNotEmpty) { return shelf.Response.notFound('Invalid URI.'); } log.message('Authorization received, processing...'); - var queryString = request.url.query; + final queryString = request.url.query; // Closing the server here is safe, since it will wait until the response // is sent to actually shut down. server.close(); @@ -248,7 +248,7 @@ Future<_Client> _authorize() async { return shelf.Response.found('https://pub.dev/authorized'); }); - var authUrl = grant.getAuthorizationUrl( + final authUrl = grant.getAuthorizationUrl( Uri.parse('http://localhost:${server.port}'), scopes: _scopes, ); @@ -259,7 +259,7 @@ Future<_Client> _authorize() async { 'Then click "Allow access".\n\n' 'Waiting for your authorization...'); - var client = await completer.future; + final client = await completer.future; log.message('Successfully authorized.\n'); return client; } @@ -457,15 +457,15 @@ class _AuthorizationCodeGrant { } _state = _State.awaitingResponse; - var scopeList = scopes?.toList() ?? []; - var codeChallenge = base64Url + final scopeList = scopes?.toList() ?? []; + final codeChallenge = base64Url .encode(sha256.convert(ascii.encode(_codeVerifier)).bytes) .replaceAll('=', ''); _redirectEndpoint = redirect; _scopes = scopeList; _stateString = state; - var parameters = { + final parameters = { 'response_type': 'code', 'client_id': identifier, 'redirect_uri': redirect.toString(), @@ -520,9 +520,9 @@ class _AuthorizationCodeGrant { } if (parameters.containsKey('error')) { - var description = parameters['error_description']; - var uriString = parameters['error_uri']; - var uri = uriString == null ? null : Uri.parse(uriString); + final description = parameters['error_description']; + final uriString = parameters['error_uri']; + final uri = uriString == null ? null : Uri.parse(uriString); throw _AuthorizationException(parameters['error']!, description, uri); } else if (!parameters.containsKey('code')) { throw FormatException('Invalid OAuth response for ' @@ -562,18 +562,18 @@ class _AuthorizationCodeGrant { /// This works just like [handleAuthorizationCode], except it doesn't validate /// the state beforehand. Future<_Client> _handleAuthorizationCode(String? authorizationCode) async { - var startTime = DateTime.now(); + final startTime = DateTime.now(); - var headers = {}; + final headers = {}; - var body = { + final body = { 'grant_type': 'authorization_code', 'code': authorizationCode, 'redirect_uri': _redirectEndpoint.toString(), 'code_verifier': _codeVerifier, }; - var secret = this.secret; + final secret = this.secret; if (_basicAuth && secret != null) { headers['Authorization'] = _basicAuthHeader(identifier, secret); } else { @@ -583,10 +583,10 @@ class _AuthorizationCodeGrant { if (secret != null) body['client_secret'] = secret; } - var response = + final response = await _httpClient!.post(tokenEndpoint, headers: headers, body: body); - var credentials = _handleAccessTokenResponse( + final credentials = _handleAccessTokenResponse( response, tokenEndpoint, startTime, @@ -772,7 +772,7 @@ class _Client extends http.BaseClient { } request.headers['authorization'] = 'Bearer ${credentials.accessToken}'; - var response = await _httpClient!.send(request); + final response = await _httpClient!.send(request); if (response.statusCode != 401) return response; if (!response.headers.containsKey('www-authenticate')) return response; @@ -786,11 +786,11 @@ class _Client extends http.BaseClient { return response; } - var challenge = challenges + final challenge = challenges .firstWhereOrNull((challenge) => challenge.scheme == 'bearer'); if (challenge == null) return response; - var params = challenge.parameters; + final params = challenge.parameters; if (!params.containsKey('error')) return response; throw _AuthorizationException( @@ -919,7 +919,7 @@ class Credentials { /// called. However, since the client's expiration date is kept a few seconds /// earlier than the server's, there should be enough leeway to rely on this. bool get isExpired { - var expiration = this.expiration; + final expiration = this.expiration; return expiration != null && DateTime.now().isAfter(expiration); } @@ -994,20 +994,20 @@ class Credentials { ); for (var stringField in ['refreshToken', 'idToken', 'tokenEndpoint']) { - var value = parsed[stringField]; + final value = parsed[stringField]; validate( value == null || value is String, 'field "$stringField" was not a string, was "$value"', ); } - var scopes = parsed['scopes']; + final scopes = parsed['scopes']; validate( scopes == null || scopes is List, 'field "scopes" was not a list, was "$scopes"', ); - var tokenEndpoint = parsed['tokenEndpoint']; + final tokenEndpoint = parsed['tokenEndpoint']; Uri? tokenEndpointUri; if (tokenEndpoint != null) { tokenEndpointUri = Uri.parse(tokenEndpoint as String); @@ -1075,8 +1075,8 @@ class Credentials { throw ArgumentError('secret may not be passed without identifier.'); } - var startTime = DateTime.now(); - var tokenEndpoint = this.tokenEndpoint; + final startTime = DateTime.now(); + final tokenEndpoint = this.tokenEndpoint; if (refreshToken == null) { throw StateError("Can't refresh credentials without a refresh " 'token.'); @@ -1085,9 +1085,9 @@ class Credentials { 'endpoint.'); } - var headers = {}; + final headers = {}; - var body = {'grant_type': 'refresh_token', 'refresh_token': refreshToken}; + final body = {'grant_type': 'refresh_token', 'refresh_token': refreshToken}; if (scopes.isNotEmpty) body['scope'] = scopes.join(_delimiter); if (basicAuth && secret != null) { @@ -1097,9 +1097,9 @@ class Credentials { if (secret != null) body['client_secret'] = secret; } - var response = + final response = await httpClient.post(tokenEndpoint, headers: headers, body: body); - var credentials = _handleAccessTokenResponse( + final credentials = _handleAccessTokenResponse( response, tokenEndpoint, startTime, @@ -1173,12 +1173,12 @@ Credentials _handleAccessTokenResponse( _handleErrorResponse(response, tokenEndpoint, getParameters); } - var contentTypeString = response.headers['content-type']; + final contentTypeString = response.headers['content-type']; if (contentTypeString == null) { throw const FormatException('Missing Content-Type string.'); } - var parameters = + final parameters = getParameters(MediaType.parse(contentTypeString), response.body); for (var requiredParameter in ['access_token', 'token_type']) { @@ -1219,7 +1219,7 @@ Credentials _handleAccessTokenResponse( } for (var name in ['refresh_token', 'id_token', 'scope']) { - var value = parameters[name]; + final value = parameters[name]; if (value != null && value is! String) { throw FormatException( 'parameter "$name" was not a string, was "$value"', @@ -1227,10 +1227,10 @@ Credentials _handleAccessTokenResponse( } } - var scope = parameters['scope'] as String?; + final scope = parameters['scope'] as String?; if (scope != null) scopes = scope.split(delimiter); - var expiration = expiresIn == null + final expiration = expiresIn == null ? null : startTime.add(Duration(seconds: expiresIn as int) - _expirationGrace); @@ -1260,7 +1260,7 @@ void _handleErrorResponse( // off-spec. if (response.statusCode != 400 && response.statusCode != 401) { var reason = ''; - var reasonPhrase = response.reasonPhrase; + final reasonPhrase = response.reasonPhrase; if (reasonPhrase != null && reasonPhrase.isNotEmpty) { reason = ' $reasonPhrase'; } @@ -1268,11 +1268,11 @@ void _handleErrorResponse( 'with status ${response.statusCode}$reason.\n\n${response.body}'); } - var contentTypeString = response.headers['content-type']; - var contentType = + final contentTypeString = response.headers['content-type']; + final contentType = contentTypeString == null ? null : MediaType.parse(contentTypeString); - var parameters = getParameters(contentType, response.body); + final parameters = getParameters(contentType, response.body); if (!parameters.containsKey('error')) { throw const FormatException('did not contain required parameter "error"'); @@ -1282,16 +1282,16 @@ void _handleErrorResponse( } for (var name in ['error_description', 'error_uri']) { - var value = parameters[name]; + final value = parameters[name]; if (value != null && value is! String) { throw FormatException('parameter "$name" was not a string, was "$value"'); } } - var uriString = parameters['error_uri'] as String?; - var uri = uriString == null ? null : Uri.parse(uriString); - var description = parameters['error_description'] as String?; + final uriString = parameters['error_uri'] as String?; + final uri = uriString == null ? null : Uri.parse(uriString); + final description = parameters['error_description'] as String?; throw _AuthorizationException( parameters['error'] as String, description, @@ -1320,7 +1320,7 @@ Map parseJsonParameters(MediaType? contentType, String body) { ); } - var untypedParameters = jsonDecode(body); + final untypedParameters = jsonDecode(body); if (untypedParameters is Map) { return untypedParameters; } @@ -1335,6 +1335,6 @@ Uri _addQueryParameters(Uri url, Map parameters) => url.replace( ); String _basicAuthHeader(String identifier, String secret) { - var userPass = '${Uri.encodeFull(identifier)}:${Uri.encodeFull(secret)}'; + final userPass = '${Uri.encodeFull(identifier)}:${Uri.encodeFull(secret)}'; return 'Basic ${base64Encode(ascii.encode(userPass))}'; } diff --git a/lib/src/package.dart b/lib/src/package.dart index ff6291ab0..e8c97d684 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -25,7 +25,7 @@ class Package { /// take a package's description or root directory into account, so multiple /// distinct packages may order the same. static int orderByNameAndVersion(Package a, Package b) { - var name = a.name.compareTo(b.name); + final name = a.name.compareTo(b.name); if (name != 0) return name; return a.version.compareTo(b.version); @@ -122,7 +122,7 @@ class Package { // If the entire package directory is ignored, don't consider it part of a // git repo. `git check-ignore` will return a status code of 0 for // ignored, 1 for not ignored, and 128 for not a Git repo. - var result = runProcessSync( + final result = runProcessSync( git.command!, ['check-ignore', '--quiet', '.'], workingDir: dir, @@ -250,8 +250,8 @@ See $workspacesDocUrl for more information. /// /// To convert them to paths relative to the package root, use [p.relative]. List listFiles({String? beneath, bool recursive = true}) { - var packageDir = dir; - var root = git.repoRoot(packageDir) ?? packageDir; + final packageDir = dir; + final root = git.repoRoot(packageDir) ?? packageDir; beneath = p .toUri( p.normalize( diff --git a/lib/src/package_graph.dart b/lib/src/package_graph.dart index 158b11a8b..b749896ed 100644 --- a/lib/src/package_graph.dart +++ b/lib/src/package_graph.dart @@ -60,7 +60,7 @@ class PackageGraph { } if (_transitiveDependencies == null) { - var closure = transitiveClosure( + final closure = transitiveClosure( mapMap>( packages, value: (_, package) => package.dependencies.keys, @@ -70,7 +70,7 @@ class PackageGraph { mapMap, String, Set>( closure, value: (depender, names) { - var set = names.map((name) => packages[name]!).toSet(); + final set = names.map((name) => packages[name]!).toSet(); set.add(packages[depender]!); return set; }, diff --git a/lib/src/package_name.dart b/lib/src/package_name.dart index dcc771247..d47a446b7 100644 --- a/lib/src/package_name.dart +++ b/lib/src/package_name.dart @@ -34,7 +34,7 @@ class PackageRef { detail ??= PackageDetail.defaults; if (isRoot) return name; - var buffer = StringBuffer(name); + final buffer = StringBuffer(name); if (detail.showSource ?? description is! HostedDescription) { buffer.write(' from ${description.source}'); if (detail.showDescription) { @@ -110,7 +110,7 @@ class PackageId { String toString([PackageDetail? detail]) { detail ??= PackageDetail.defaults; - var buffer = StringBuffer(name); + final buffer = StringBuffer(name); if (detail.showVersion ?? !isRoot) buffer.write(' $version'); if (!isRoot && @@ -156,7 +156,7 @@ class PackageRange { String toString([PackageDetail? detail]) { detail ??= PackageDetail.defaults; - var buffer = StringBuffer(name); + final buffer = StringBuffer(name); if (detail.showVersion ?? _showVersionConstraint) { buffer.write(' $constraint'); } @@ -183,10 +183,10 @@ class PackageRange { if (constraint is! VersionRange) return this; if (constraint.toString().startsWith('^')) return this; - var range = constraint as VersionRange; + final range = constraint as VersionRange; if (!range.includeMin) return this; if (range.includeMax) return this; - var min = range.min; + final min = range.min; if (min == null) return this; if (range.max == min.nextBreaking.firstPreRelease) { return PackageRange(_ref, VersionConstraint.compatibleWith(min)); diff --git a/lib/src/progress.dart b/lib/src/progress.dart index ebddb2f71..cff71d3b1 100644 --- a/lib/src/progress.dart +++ b/lib/src/progress.dart @@ -35,7 +35,7 @@ class Progress { Progress(this._message, {bool fine = false}) { _stopwatch.start(); - var level = fine ? log.Level.fine : log.Level.message; + final level = fine ? log.Level.fine : log.Level.message; // The animation is only shown when it would be meaningful to a human. // That means we're writing a visible message to a TTY at normal log levels @@ -121,7 +121,7 @@ class Progress { // rather than using `\r` to erase the entire line ensures that we don't // spam progress lines if they're wider than the terminal width. stdout.write('\b' * _timeLength); - var time = _time; + final time = _time; _timeLength = time.length; stdout.write(log.gray(time)); } diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index deabc9002..8f14cad83 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -201,7 +201,7 @@ class Pubspec extends PubspecBase { /// Parses the "environment" field in [parent] and returns a map from SDK /// identifiers to constraints on those SDKs. Map _parseEnvironment(YamlMap parent) { - var yaml = parent['environment']; + final yaml = parent['environment']; final VersionConstraint originalDartSdkConstraint; if (yaml == null) { originalDartSdkConstraint = VersionConstraint.any; @@ -217,7 +217,7 @@ class Pubspec extends PubspecBase { _FileType.pubspec, ); } - var constraints = { + final constraints = { 'dart': SdkConstraint.interpretDartSdkConstraint( originalDartSdkConstraint, defaultUpperBoundConstraint: _includeDefaultSdkConstraint @@ -271,8 +271,8 @@ class Pubspec extends PubspecBase { bool allowOverridesFile = false, required Description containingDescription, }) { - var pubspecPath = p.join(packageDir, pubspecYamlFilename); - var overridesPath = p.join(packageDir, pubspecOverridesFilename); + final pubspecPath = p.join(packageDir, pubspecYamlFilename); + final overridesPath = p.join(packageDir, pubspecOverridesFilename); if (!fileExists(pubspecPath)) { throw FileException( // Make the package dir absolute because for the entrypoint it'll just @@ -473,7 +473,7 @@ class Pubspec extends PubspecBase { List _collectErrorsFor( List toCheck, ) { - var errors = []; + final errors = []; void collectError(void Function() fn) { try { fn(); @@ -548,7 +548,7 @@ Map _parseDependencies( Description containingDescription, { _FileType fileType = _FileType.pubspec, }) { - var dependencies = {}; + final dependencies = {}; // Allow an empty dependencies key. if (node == null || node.value == null) return dependencies; @@ -557,7 +557,7 @@ Map _parseDependencies( _error('"$field" field must be a map.', node.span); } - var nonStringNode = node.nodes.keys + final nonStringNode = node.nodes.keys .firstWhereOrNull((e) => e is YamlScalar && e.value is! String); if (nonStringNode != null) { _error( @@ -568,14 +568,14 @@ Map _parseDependencies( node.nodes.forEach( (nameNode, specNode) { - var name = (nameNode as YamlNode).value; + final name = (nameNode as YamlNode).value; if (name is! String) { _error('A dependency name must be a string.', nameNode.span); } if (!packageNameRegExp.hasMatch(name)) { _error('Not a valid package name.', nameNode.span); } - var spec = specNode.value; + final spec = specNode.value; if (packageName != null && name == packageName) { _error('A package may not list itself as a dependency.', nameNode.span); } @@ -607,7 +607,10 @@ Map _parseDependencies( sourceName = 'hosted'; } else { switch (otherEntries.single) { - case MapEntry(key: YamlScalar(value: String s), value: final d): + case MapEntry( + key: YamlScalar(value: final String s), + value: final d + ): sourceName = s; descriptionNode = d; case MapEntry(key: final k, value: _): @@ -625,7 +628,7 @@ Map _parseDependencies( } // Let the source validate the description. - var ref = _wrapFormatException( + final ref = _wrapFormatException( 'description', descriptionNode?.span, () { @@ -670,7 +673,7 @@ VersionConstraint _parseVersionConstraint( 'version constraint', node.span, () { - var constraint = VersionConstraint.parse(value); + final constraint = VersionConstraint.parse(value); return constraint; }, packageName, diff --git a/lib/src/pubspec_parse.dart b/lib/src/pubspec_parse.dart index 48a7f3df1..df5343ffa 100644 --- a/lib/src/pubspec_parse.dart +++ b/lib/src/pubspec_parse.dart @@ -197,7 +197,7 @@ abstract class PubspecBase { if (_executables != null) return _executables!; _executables = {}; - var yaml = fields['executables']; + final yaml = fields['executables']; if (yaml == null) return _executables!; if (yaml is! YamlMap) { @@ -207,7 +207,7 @@ abstract class PubspecBase { ); } - var yamlMap = yaml; + final yamlMap = yaml; yamlMap.nodes.forEach((key, value) { key = key as YamlNode; @@ -228,11 +228,11 @@ abstract class PubspecBase { final valuePattern = RegExp(r'[/\\]'); _executables![keyValue] = switch (value.value) { null => keyValue, - String s when valuePattern.hasMatch(s) => _error( + final String s when valuePattern.hasMatch(s) => _error( '"executables" values may not contain path separators.', value.span, ), - String s => s, + final String s => s, _ => _error('"executables" values must be strings or null.', value.span) }; }); diff --git a/lib/src/sdk/dart.dart b/lib/src/sdk/dart.dart index f98477be9..39e364d65 100644 --- a/lib/src/sdk/dart.dart +++ b/lib/src/sdk/dart.dart @@ -27,7 +27,7 @@ class DartSdk extends Sdk { static final String _rootDirectory = () { // If DART_ROOT is specified, then this always points to the Dart SDK - if (Platform.environment['DART_ROOT'] case var root?) { + if (Platform.environment['DART_ROOT'] case final root?) { return root; } @@ -35,18 +35,18 @@ class DartSdk extends Sdk { // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is // "/path/to/sdk". - var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); + final aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable)); assert(fileExists(p.join(aboveExecutable, 'version'))); return aboveExecutable; }(); /// The loaded `sdk_packages.yaml` file if present. static final SdkPackageConfig? _sdkPackages = () { - var path = p.join(_rootDirectory, 'sdk_packages.yaml'); + final path = p.join(_rootDirectory, 'sdk_packages.yaml'); if (!fileExists(path)) return null; final text = readTextFile(path); final yaml = loadYaml(text) as YamlMap; - var config = SdkPackageConfig.fromYaml(yaml); + final config = SdkPackageConfig.fromYaml(yaml); if (config.sdk != 'dart') { throw FormatException( 'Expected a configuration for the `dart` sdk but got one for ' @@ -63,7 +63,7 @@ class DartSdk extends Sdk { // Some of the pub integration tests require an SDK version number, but the // tests on the bots are not run from a built SDK so this lets us avoid // parsing the missing version file. - var sdkVersion = Platform.environment['_PUB_TEST_SDK_VERSION'] ?? + final sdkVersion = Platform.environment['_PUB_TEST_SDK_VERSION'] ?? Platform.version.split(' ').first; return Version.parse(sdkVersion); @@ -79,12 +79,12 @@ class DartSdk extends Sdk { @override String? packagePath(String name) { if (!isAvailable) return null; - var sdkPackages = _sdkPackages; + final sdkPackages = _sdkPackages; if (sdkPackages == null) return null; - var package = sdkPackages.packages[name]; + final package = sdkPackages.packages[name]; if (package == null) return null; - var packagePath = p.joinAll([_rootDirectory, ...package.path.split('/')]); + final packagePath = p.joinAll([_rootDirectory, ...package.path.split('/')]); if (dirExists(packagePath)) return packagePath; return null; diff --git a/lib/src/sdk/flutter.dart b/lib/src/sdk/flutter.dart index bb3cf12db..993f4ac06 100644 --- a/lib/src/sdk/flutter.dart +++ b/lib/src/sdk/flutter.dart @@ -106,10 +106,10 @@ class FlutterSdk extends Sdk { // `$flutter/bin/cache/pkg`. This checks both locations in order. If [name] // exists in neither place, it returns the `$flutter/packages` location // which is more human-readable for error messages. - var packagePath = p.join(rootDirectory!, 'packages', name); + final packagePath = p.join(rootDirectory!, 'packages', name); if (dirExists(packagePath)) return packagePath; - var cachePath = p.join(rootDirectory!, 'bin', 'cache', 'pkg', name); + final cachePath = p.join(rootDirectory!, 'bin', 'cache', 'pkg', name); if (dirExists(cachePath)) return cachePath; return null; diff --git a/lib/src/sdk/fuchsia.dart b/lib/src/sdk/fuchsia.dart index cdd41bde9..8e401887d 100644 --- a/lib/src/sdk/fuchsia.dart +++ b/lib/src/sdk/fuchsia.dart @@ -42,7 +42,7 @@ class FuchsiaSdk extends Sdk { String? packagePath(String name) { if (!isAvailable) return null; - var packagePath = p.join(_rootDirectory!, 'packages', name); + final packagePath = p.join(_rootDirectory!, 'packages', name); if (dirExists(packagePath)) return packagePath; return null; diff --git a/lib/src/solver/failure.dart b/lib/src/solver/failure.dart index d3d4293db..ab136f90e 100644 --- a/lib/src/solver/failure.dart +++ b/lib/src/solver/failure.dart @@ -31,7 +31,7 @@ class SolveFailure implements ApplicationException { /// which one is returned. PackageNotFoundException? get packageNotFound { for (var incompatibility in incompatibility.externalIncompatibilities) { - var cause = incompatibility.cause; + final cause = incompatibility.cause; if (cause is PackageNotFoundIncompatibilityCause) return cause.exception; } return null; @@ -90,7 +90,7 @@ class _Writer { incompatibility, (value) => value + 1, ifAbsent: () { - var cause = incompatibility.cause; + final cause = incompatibility.cause; if (cause is ConflictCause) { _countDerivations(cause.conflict); _countDerivations(cause.other); @@ -101,7 +101,7 @@ class _Writer { } String write() { - var buffer = StringBuffer(); + final buffer = StringBuffer(); // Find all notices from incompatibility causes. This allows an // [IncompatibilityCause] to provide a notice that is printed before the @@ -126,7 +126,7 @@ class _Writer { // Only add line numbers if the derivation actually needs to refer to a line // by number. - var padding = + final padding = _lineNumbers.isEmpty ? 0 : '(${_lineNumbers.values.last}) '.length; var lastWasEmpty = false; @@ -179,7 +179,7 @@ class _Writer { bool numbered = false, }) { if (numbered) { - var number = _lineNumbers.length + 1; + final number = _lineNumbers.length + 1; _lineNumbers[incompatibility] = number; _lines.add((message, number)); } else { @@ -202,18 +202,18 @@ class _Writer { }) { // Add explicit numbers for incompatibilities that are written far away // from their successors or that are used for multiple derivations. - var numbered = conclusion || _derivations[incompatibility]! > 1; - var conjunction = conclusion || incompatibility == _root ? 'So,' : 'And'; - var incompatibilityString = + final numbered = conclusion || _derivations[incompatibility]! > 1; + final conjunction = conclusion || incompatibility == _root ? 'So,' : 'And'; + final incompatibilityString = log.bold(incompatibility.toString(detailsForIncompatibility)); - var conflictClause = incompatibility.cause as ConflictCause; + final conflictClause = incompatibility.cause as ConflictCause; var detailsForCause = _detailsForCause(conflictClause); - var cause = conflictClause.conflict.cause; - var otherCause = conflictClause.other.cause; + final cause = conflictClause.conflict.cause; + final otherCause = conflictClause.other.cause; if (cause is ConflictCause && otherCause is ConflictCause) { - var conflictLine = _lineNumbers[conflictClause.conflict]; - var otherLine = _lineNumbers[conflictClause.other]; + final conflictLine = _lineNumbers[conflictClause.conflict]; + final otherLine = _lineNumbers[conflictClause.other]; if (conflictLine != null && otherLine != null) { _write( incompatibility, @@ -242,12 +242,12 @@ class _Writer { numbered: numbered, ); } else { - var singleLineConflict = _isSingleLine(cause); - var singleLineOther = _isSingleLine(otherCause); + final singleLineConflict = _isSingleLine(cause); + final singleLineOther = _isSingleLine(otherCause); if (singleLineOther || singleLineConflict) { - var first = + final first = singleLineOther ? conflictClause.conflict : conflictClause.other; - var second = + final second = singleLineOther ? conflictClause.other : conflictClause.conflict; _visit(first, detailsForCause); _visit(second, detailsForCause); @@ -272,14 +272,14 @@ class _Writer { } } } else if (cause is ConflictCause || otherCause is ConflictCause) { - var derived = cause is ConflictCause + final derived = cause is ConflictCause ? conflictClause.conflict : conflictClause.other; - var ext = cause is ConflictCause + final ext = cause is ConflictCause ? conflictClause.other : conflictClause.conflict; - var derivedLine = _lineNumbers[derived]; + final derivedLine = _lineNumbers[derived]; if (derivedLine != null) { _write( incompatibility, @@ -287,11 +287,11 @@ class _Writer { numbered: numbered, ); } else if (_isCollapsible(derived)) { - var derivedCause = derived.cause as ConflictCause; - var collapsedDerived = derivedCause.conflict.cause is ConflictCause + final derivedCause = derived.cause as ConflictCause; + final collapsedDerived = derivedCause.conflict.cause is ConflictCause ? derivedCause.conflict : derivedCause.other; - var collapsedExt = derivedCause.conflict.cause is ConflictCause + final collapsedExt = derivedCause.conflict.cause is ConflictCause ? derivedCause.other : derivedCause.conflict; @@ -359,7 +359,7 @@ class _Writer { // line number and so will need to be written explicitly. if (_derivations[incompatibility]! > 1) return false; - var cause = incompatibility.cause as ConflictCause; + final cause = incompatibility.cause as ConflictCause; // If [incompatibility] is derived from two derived incompatibilities, // there are too many transitive causes to display concisely. if (cause.conflict.cause is ConflictCause && @@ -376,7 +376,7 @@ class _Writer { // If [incompatibility]'s internal cause is numbered, collapsing it would // get too noisy. - var complex = + final complex = cause.conflict.cause is ConflictCause ? cause.conflict : cause.other; return !_lineNumbers.containsKey(complex); } @@ -394,15 +394,15 @@ class _Writer { /// but each has a different source, those incompatibilities should explicitly /// print their sources, and similarly for differing descriptions. Map _detailsForCause(ConflictCause cause) { - var conflictPackages = {}; + final conflictPackages = {}; for (var term in cause.conflict.terms) { if (term.package.isRoot) continue; conflictPackages[term.package.name] = term.package; } - var details = {}; + final details = {}; for (var term in cause.other.terms) { - var conflictPackage = conflictPackages[term.package.name]; + final conflictPackage = conflictPackages[term.package.name]; if (term.package.isRoot) continue; if (conflictPackage == null) continue; if (conflictPackage.description.source != diff --git a/lib/src/solver/incompatibility.dart b/lib/src/solver/incompatibility.dart index 15178b399..9e94968a4 100644 --- a/lib/src/solver/incompatibility.dart +++ b/lib/src/solver/incompatibility.dart @@ -25,7 +25,7 @@ class Incompatibility { /// derivation graph. Iterable get externalIncompatibilities sync* { if (cause is ConflictCause) { - var cause = this.cause as ConflictCause; + final cause = this.cause as ConflictCause; yield* cause.conflict.externalIncompatibilities; yield* cause.other.externalIncompatibilities; } else { @@ -58,10 +58,10 @@ class Incompatibility { } // Coalesce multiple terms about the same package if possible. - var byName = >{}; + final byName = >{}; for (var term in terms) { - var byRef = byName.putIfAbsent(term.package.name, () => {}); - var ref = term.package.toRef(); + final byRef = byName.putIfAbsent(term.package.name, () => {}); + final ref = term.package.toRef(); if (byRef.containsKey(ref)) { // If we have two terms that refer to the same package but have a null // intersection, they're mutually exclusive, making this incompatibility @@ -78,7 +78,7 @@ class Incompatibility { byName.values.expand((byRef) { // If there are any positive terms for a given package, we can discard // any negative terms. - var positiveTerms = + final positiveTerms = byRef.values.where((term) => term.isPositive).toList(); if (positiveTerms.isNotEmpty) return positiveTerms; @@ -99,8 +99,8 @@ class Incompatibility { if (cause is DependencyIncompatibilityCause) { assert(terms.length == 2); - var depender = terms.first; - var dependee = terms.last; + final depender = terms.first; + final dependee = terms.last; assert(depender.isPositive); assert(!dependee.isPositive); @@ -110,8 +110,9 @@ class Incompatibility { assert(terms.length == 1); assert(terms.first.isPositive); - var cause = this.cause as SdkIncompatibilityCause; - var buffer = StringBuffer(_terse(terms.first, details, allowEvery: true)); + final cause = this.cause as SdkIncompatibilityCause; + final buffer = + StringBuffer(_terse(terms.first, details, allowEvery: true)); if (cause.noNullSafetyCause) { buffer.write(' doesn\'t support null safety'); } else { @@ -133,7 +134,7 @@ class Incompatibility { assert(terms.length == 1); assert(terms.first.isPositive); - var cause = this.cause as PackageNotFoundIncompatibilityCause; + final cause = this.cause as PackageNotFoundIncompatibilityCause; return "${_terseRef(terms.first, details)} doesn't exist " '(${cause.exception.message})'; } else if (cause is UnknownSourceIncompatibilityCause) { @@ -154,7 +155,7 @@ class Incompatibility { } if (terms.length == 1) { - var term = terms.single; + final term = terms.single; if (term.constraint.isAny) { return '${_terseRef(term, details)} is ' "${term.isPositive ? 'forbidden' : 'required'}"; @@ -165,14 +166,14 @@ class Incompatibility { } if (terms.length == 2) { - var term1 = terms.first; - var term2 = terms.last; + final term1 = terms.first; + final term2 = terms.last; if (term1.isPositive == term2.isPositive) { if (term1.isPositive) { - var package1 = term1.constraint.isAny + final package1 = term1.constraint.isAny ? _terseRef(term1, details) : _terse(term1, details); - var package2 = term2.constraint.isAny + final package2 = term2.constraint.isAny ? _terseRef(term2, details) : _terse(term2, details); return '$package1 is incompatible with $package2'; @@ -183,15 +184,15 @@ class Incompatibility { } } - var positive = []; - var negative = []; + final positive = []; + final negative = []; for (var term in terms) { (term.isPositive ? positive : negative).add(_terse(term, details)); } if (positive.isNotEmpty && negative.isNotEmpty) { if (positive.length == 1) { - var positiveTerm = terms.firstWhere((term) => term.isPositive); + final positiveTerm = terms.firstWhere((term) => term.isPositive); return '${_terse(positiveTerm, details, allowEvery: true)} requires ' "${negative.join(' or ')}"; } else { @@ -218,18 +219,18 @@ class Incompatibility { int? thisLine, int? otherLine, ]) { - var requiresBoth = _tryRequiresBoth(other, details, thisLine, otherLine); + final requiresBoth = _tryRequiresBoth(other, details, thisLine, otherLine); if (requiresBoth != null) return requiresBoth; - var requiresThrough = + final requiresThrough = _tryRequiresThrough(other, details, thisLine, otherLine); if (requiresThrough != null) return requiresThrough; - var requiresForbidden = + final requiresForbidden = _tryRequiresForbidden(other, details, thisLine, otherLine); if (requiresForbidden != null) return requiresForbidden; - var buffer = StringBuffer(toString(details)); + final buffer = StringBuffer(toString(details)); if (thisLine != null) buffer.write(' $thisLine'); buffer.write(' and ${other.toString(details)}'); if (otherLine != null) buffer.write(' $thisLine'); @@ -248,24 +249,24 @@ class Incompatibility { ]) { if (terms.length == 1 || other.terms.length == 1) return null; - var thisPositive = _singleTermWhere((term) => term.isPositive); + final thisPositive = _singleTermWhere((term) => term.isPositive); if (thisPositive == null) return null; - var otherPositive = other._singleTermWhere((term) => term.isPositive); + final otherPositive = other._singleTermWhere((term) => term.isPositive); if (otherPositive == null) return null; if (thisPositive.package != otherPositive.package) return null; - var thisNegatives = terms + final thisNegatives = terms .where((term) => !term.isPositive) .map((term) => _terse(term, details)) .join(' or '); - var otherNegatives = other.terms + final otherNegatives = other.terms .where((term) => !term.isPositive) .map((term) => _terse(term, details)) .join(' or '); - var buffer = + final buffer = StringBuffer('${_terse(thisPositive, details, allowEvery: true)} '); - var isDependency = cause is DependencyIncompatibilityCause && + final isDependency = cause is DependencyIncompatibilityCause && other.cause is DependencyIncompatibilityCause; buffer.write(isDependency ? 'depends on' : 'requires'); buffer.write(' both $thisNegatives'); @@ -287,12 +288,12 @@ class Incompatibility { ]) { if (terms.length == 1 || other.terms.length == 1) return null; - var thisNegative = _singleTermWhere((term) => !term.isPositive); - var otherNegative = other._singleTermWhere((term) => !term.isPositive); + final thisNegative = _singleTermWhere((term) => !term.isPositive); + final otherNegative = other._singleTermWhere((term) => !term.isPositive); if (thisNegative == null && otherNegative == null) return null; - var thisPositive = _singleTermWhere((term) => term.isPositive); - var otherPositive = other._singleTermWhere((term) => term.isPositive); + final thisPositive = _singleTermWhere((term) => term.isPositive); + final otherPositive = other._singleTermWhere((term) => term.isPositive); Incompatibility prior; Term priorNegative; @@ -321,15 +322,15 @@ class Incompatibility { return null; } - var priorPositives = prior.terms.where((term) => term.isPositive); + final priorPositives = prior.terms.where((term) => term.isPositive); - var buffer = StringBuffer(); + final buffer = StringBuffer(); if (priorPositives.length > 1) { - var priorString = + final priorString = priorPositives.map((term) => _terse(term, details)).join(' or '); buffer.write('if $priorString then '); } else { - var verb = prior.cause is DependencyIncompatibilityCause + final verb = prior.cause is DependencyIncompatibilityCause ? 'depends on' : 'requires'; buffer.write('${_terse(priorPositives.first, details, allowEvery: true)} ' @@ -386,15 +387,15 @@ class Incompatibility { latterLine = otherLine; } - var negative = prior._singleTermWhere((term) => !term.isPositive); + final negative = prior._singleTermWhere((term) => !term.isPositive); if (negative == null) return null; if (!negative.inverse.satisfies(latter.terms.first)) return null; - var positives = prior.terms.where((term) => term.isPositive); + final positives = prior.terms.where((term) => term.isPositive); - var buffer = StringBuffer(); + final buffer = StringBuffer(); if (positives.length > 1) { - var priorString = + final priorString = positives.map((term) => _terse(term, details)).join(' or '); buffer.write('if $priorString then '); } else { @@ -407,7 +408,7 @@ class Incompatibility { } if (latter.cause is UnknownSourceIncompatibilityCause) { - var package = latter.terms.first.package; + final package = latter.terms.first.package; buffer.write('${package.name} '); if (priorLine != null) buffer.write('($priorLine) '); buffer.write('from unknown source "${package.source}"'); @@ -419,7 +420,7 @@ class Incompatibility { if (priorLine != null) buffer.write('($priorLine) '); if (latter.cause is SdkIncompatibilityCause) { - var cause = latter.cause as SdkIncompatibilityCause; + final cause = latter.cause as SdkIncompatibilityCause; if (cause.noNullSafetyCause) { buffer.write('which doesn\'t support null safety'); } else { diff --git a/lib/src/solver/package_lister.dart b/lib/src/solver/package_lister.dart index c46df0ab7..5f48a2832 100644 --- a/lib/src/solver/package_lister.dart +++ b/lib/src/solver/package_lister.dart @@ -85,7 +85,7 @@ class PackageLister { /// All versions of the package, sorted by [Version.compareTo]. Future> get _versions => _versionsMemo.runOnce(() async { - var cachedVersions = _ref.isRoot + final cachedVersions = _ref.isRoot ? [ PackageId( _ref.name, @@ -170,17 +170,17 @@ class PackageLister { final locked = _locked; if (locked != null && constraint.allows(locked.version)) return locked; - var versions = await _versions; + final versions = await _versions; // If [constraint] has a minimum (or a maximum in downgrade mode), we can // bail early once we're past it. var isPastLimit = (Version _) => false; if (constraint is VersionRange) { if (_isDowngrade) { - var max = constraint.max; + final max = constraint.max; if (max != null) isPastLimit = (version) => version > max; } else { - var min = constraint.min; + final min = constraint.min; if (min != null) isPastLimit = (version) => version < min; } } @@ -251,7 +251,7 @@ class PackageLister { id.version == _locked.version) { if (_listedLockedVersion) return const []; - var depender = id.toRange(); + final depender = id.toRange(); _listedLockedVersion = true; for (var sdk in sdks.values) { if (!_matchesSdkConstraint(pubspec, sdk)) { @@ -286,8 +286,8 @@ class PackageLister { return entries.map((range) => _dependency(depender, range)).toList(); } - var versions = await _versions; - var index = lowerBound( + final versions = await _versions; + final index = lowerBound( versions, id, compare: (PackageId id1, PackageId id2) => @@ -297,29 +297,29 @@ class PackageLister { assert(versions[index].version == id.version); for (var sdk in sdks.values) { - var sdkIncompatibility = await _checkSdkConstraint(index, sdk); + final sdkIncompatibility = await _checkSdkConstraint(index, sdk); if (sdkIncompatibility != null) return [sdkIncompatibility]; } // Don't recompute dependencies that have already been emitted. - var dependencies = Map.from(pubspec.dependencies); + final dependencies = Map.from(pubspec.dependencies); for (var package in dependencies.keys.toList()) { if (_overriddenPackages.contains(package)) { dependencies.remove(package); continue; } - var constraint = _alreadyListedDependencies[package]; + final constraint = _alreadyListedDependencies[package]; if (constraint != null && constraint.allows(id.version)) { dependencies.remove(package); } } - var lower = await _dependencyBounds(dependencies, index, upper: false); - var upper = await _dependencyBounds(dependencies, index); + final lower = await _dependencyBounds(dependencies, index, upper: false); + final upper = await _dependencyBounds(dependencies, index); return ordered(dependencies.keys).map((package) { - var constraint = VersionRange( + final constraint = VersionRange( min: lower[package], includeMin: true, max: upper[package], @@ -351,15 +351,15 @@ class PackageLister { /// /// Otherwise, returns `null`. Future _checkSdkConstraint(int index, Sdk sdk) async { - var versions = await _versions; + final versions = await _versions; bool allowsSdk(Pubspec pubspec) => _matchesSdkConstraint(pubspec, sdk); if (allowsSdk(await _describeSafe(versions[index]))) return null; - var (boundsFirstIndex, boundsLastIndex) = + final (boundsFirstIndex, boundsLastIndex) = await _findBounds(index, (pubspec) => !allowsSdk(pubspec)); - var incompatibleVersions = VersionRange( + final incompatibleVersions = VersionRange( min: boundsFirstIndex == 0 ? null : versions[boundsFirstIndex].version, includeMin: true, max: boundsLastIndex == versions.length - 1 @@ -369,10 +369,10 @@ class PackageLister { ); _knownInvalidVersions = incompatibleVersions.union(_knownInvalidVersions); - var sdkConstraint = await foldAsync( + final sdkConstraint = await foldAsync( slice(versions, boundsFirstIndex, boundsLastIndex + 1), VersionConstraint.empty, (previous, version) async { - var pubspec = await _describeSafe(version); + final pubspec = await _describeSafe(version); return previous.union( pubspec.sdkConstraints[sdk.identifier]?.effectiveConstraint ?? VersionConstraint.any, @@ -393,7 +393,7 @@ class PackageLister { int start, bool Function(Pubspec) match, ) async { - var versions = await _versions; + final versions = await _versions; var first = start - 1; while (first > 0) { @@ -423,19 +423,19 @@ class PackageLister { int index, { bool upper = true, }) async { - var versions = await _versions; - var bounds = {}; + final versions = await _versions; + final bounds = {}; var previous = versions[index]; outer: for (var id in upper ? versions.skip(index + 1) : versions.reversed.skip(versions.length - index)) { - var pubspec = await _describeSafe(id); + final pubspec = await _describeSafe(id); // The upper bound is exclusive and so is the first package with a // different dependency. The lower bound is inclusive, and so is the last // package with the same dependency. - var boundary = (upper ? id : previous).version; + final boundary = (upper ? id : previous).version; // Once we hit an incompatible version, it doesn't matter whether it has // the same dependencies. @@ -482,7 +482,7 @@ class PackageLister { bool _matchesSdkConstraint(Pubspec pubspec, Sdk sdk) { if (_overriddenPackages.contains(pubspec.name)) return true; - var constraint = pubspec.sdkConstraints[sdk.identifier]; + final constraint = pubspec.sdkConstraints[sdk.identifier]; if (constraint == null) return true; return sdk.isAvailable && diff --git a/lib/src/solver/partial_solution.dart b/lib/src/solver/partial_solution.dart index cc3aeaaa2..2e6387acd 100644 --- a/lib/src/solver/partial_solution.dart +++ b/lib/src/solver/partial_solution.dart @@ -91,9 +91,9 @@ class PartialSolution { void backtrack(int decisionLevel) { _backtracking = true; - var packages = {}; + final packages = {}; while (_assignments.last.decisionLevel > decisionLevel) { - var removed = _assignments.removeLast(); + final removed = _assignments.removeLast(); packages.add(removed.package.name); if (removed.isDecision) _decisions.remove(removed.package.name); } @@ -113,17 +113,17 @@ class PartialSolution { /// Registers [assignment] in [_positive] or [_negative]. void _register(Assignment assignment) { - var name = assignment.package.name; - var oldPositive = _positive[name]; + final name = assignment.package.name; + final oldPositive = _positive[name]; if (oldPositive != null) { _positive[name] = oldPositive.intersect(assignment); return; } - var ref = assignment.package.toRef(); - var negativeByRef = _negative[name]; - var oldNegative = negativeByRef == null ? null : negativeByRef[ref]; - var term = + final ref = assignment.package.toRef(); + final negativeByRef = _negative[name]; + final oldNegative = negativeByRef == null ? null : negativeByRef[ref]; + final term = oldNegative == null ? assignment : assignment.intersect(oldNegative)!; if (term.isPositive) { @@ -173,18 +173,18 @@ class PartialSolution { /// Returns the relationship between the package versions allowed by all /// assignments in [this] and those allowed by [term]. SetRelation relation(Term term) { - var positive = _positive[term.package.name]; + final positive = _positive[term.package.name]; if (positive != null) return positive.relation(term); // If there are no assignments related to [term], that means the // assignments allow any version of any package, which is a superset of // [term]. - var byRef = _negative[term.package.name]; + final byRef = _negative[term.package.name]; if (byRef == null) return SetRelation.overlapping; // not foo from git is a superset of foo from hosted // not foo from git overlaps not foo from hosted - var negative = byRef[term.package.toRef()]; + final negative = byRef[term.package.toRef()]; if (negative == null) return SetRelation.overlapping; return negative.relation(term); diff --git a/lib/src/solver/reformat_ranges.dart b/lib/src/solver/reformat_ranges.dart index fe0f00303..bce2d1540 100644 --- a/lib/src/solver/reformat_ranges.dart +++ b/lib/src/solver/reformat_ranges.dart @@ -40,18 +40,18 @@ Incompatibility reformatRanges( /// Returns [term] with the upper and lower bounds of its package range /// reformatted if necessary. Term _reformatTerm(Map packageListers, Term term) { - var versions = packageListers[term.package.toRef()]?.cachedVersions ?? []; + final versions = packageListers[term.package.toRef()]?.cachedVersions ?? []; if (term.package.constraint is! VersionRange) return term; if (term.package.constraint is Version) return term; - var range = term.package.constraint as VersionRange; + final range = term.package.constraint as VersionRange; - var min = _reformatMin(versions, range); - var maxInfo = reformatMax(versions, range); + final min = _reformatMin(versions, range); + final maxInfo = reformatMax(versions, range); if (min == null && maxInfo == null) return term; - var (max, includeMax) = maxInfo ?? (range.max, range.includeMax); + final (max, includeMax) = maxInfo ?? (range.max, range.includeMax); return Term( term.package @@ -73,13 +73,13 @@ Term _reformatTerm(Map packageListers, Term term) { /// Returns the new minimum version to use for [range], or `null` if it doesn't /// need to be reformatted. Version? _reformatMin(List versions, VersionRange range) { - var min = range.min; + final min = range.min; if (min == null) return null; if (!range.includeMin) return null; if (!min.isFirstPreRelease) return null; - var index = _lowerBound(versions, min); - var next = index == versions.length ? null : versions[index].version; + final index = _lowerBound(versions, min); + final next = index == versions.length ? null : versions[index].version; // If there's a real pre-release version of [range.min], use that as the min. // Otherwise, use the release version. @@ -99,8 +99,8 @@ Version? _reformatMin(List versions, VersionRange range) { // `alwaysIncludeMaxPreRelease = false` for discovering when a max-bound // should not include prereleases. - var max = range.max; - var min = range.min; + final max = range.max; + final min = range.min; if (max == null) return null; if (range.includeMax) return null; if (max.isPreRelease) return null; @@ -109,8 +109,8 @@ Version? _reformatMin(List versions, VersionRange range) { return null; } - var index = _lowerBound(versions, max); - var previous = index == 0 ? null : versions[index - 1].version; + final index = _lowerBound(versions, max); + final previous = index == 0 ? null : versions[index - 1].version; return previous != null && equalsIgnoringPreRelease(previous, max) ? (previous, true) @@ -128,8 +128,8 @@ int _lowerBound(List ids, Version version) { var min = 0; var max = ids.length; while (min < max) { - var mid = min + ((max - min) >> 1); - var id = ids[mid]; + final mid = min + ((max - min) >> 1); + final id = ids[mid]; if (id.version.compareTo(version) < 0) { min = mid + 1; } else { diff --git a/lib/src/solver/report.dart b/lib/src/solver/report.dart index 6154d3235..0736ce4dd 100644 --- a/lib/src/solver/report.dart +++ b/lib/src/solver/report.dart @@ -145,7 +145,7 @@ $contentHashesDocumentationUrl /// packages. Future summarize(int changes) async { // Count how many dependencies actually changed. - var dependencies = _newLockFile.packages.keys.toSet(); + final dependencies = _newLockFile.packages.keys.toSet(); dependencies.addAll(_previousLockFile.packages.keys); dependencies.remove(_rootPubspec.name); @@ -210,7 +210,7 @@ $contentHashesDocumentationUrl Future _reportChanges() async { final output = StringBuffer(); // Show the new set of dependencies ordered by name. - var names = _newLockFile.packages.keys.toList(); + final names = _newLockFile.packages.keys.toList(); names.remove(_rootPubspec.name); names.sort(); var changes = 0; @@ -218,7 +218,7 @@ $contentHashesDocumentationUrl changes += await _reportPackage(name, output) ? 1 : 0; } // Show any removed ones. - var removed = _previousLockFile.packages.keys.toSet(); + final removed = _previousLockFile.packages.keys.toSet(); removed.removeAll(names); removed.remove(_rootPubspec.name); // Never consider root. if (removed.isNotEmpty) { @@ -335,11 +335,11 @@ $contentHashesDocumentationUrl StringBuffer output, { bool alwaysShow = false, }) async { - var newId = _newLockFile.packages[name]; - var oldId = _previousLockFile.packages[name]; - var id = newId ?? oldId!; + final newId = _newLockFile.packages[name]; + final oldId = _previousLockFile.packages[name]; + final id = newId ?? oldId!; - var isOverridden = _rootPubspec.dependencyOverrides.containsKey(id.name); + final isOverridden = _rootPubspec.dependencyOverrides.containsKey(id.name); // If the package was previously a dependency but the dependency has // changed in some way. @@ -388,7 +388,7 @@ $contentHashesDocumentationUrl // See if there are any newer versions of the package that we were // unable to upgrade to. if (newId != null && _type != SolveType.downgrade) { - var versions = _availableVersions[newId.name]!; + final versions = _availableVersions[newId.name]!; var newerStable = false; var newerUnstable = false; @@ -487,7 +487,7 @@ $contentHashesDocumentationUrl final oldDependencyType = dependencyType(_previousLockFile, name); final newDependencyType = dependencyType(_newLockFile, name); - var dependencyTypeChanged = oldId != null && + final dependencyTypeChanged = oldId != null && newId != null && oldDependencyType != newDependencyType; @@ -545,7 +545,7 @@ $contentHashesDocumentationUrl output.write(id.version); if (id.source != _cache.defaultSource) { - var description = id.description.format(); + final description = id.description.format(); output.write(' from ${id.source} $description'); } } diff --git a/lib/src/solver/result.dart b/lib/src/solver/result.dart index a53c17cc6..36925e3b8 100644 --- a/lib/src/solver/result.dart +++ b/lib/src/solver/result.dart @@ -80,13 +80,13 @@ class SolveResult { // Don't factor in overridden dependencies' SDK constraints, because we'll // accept those packages even if their constraints don't match. - var nonOverrides = pubspecs.values + final nonOverrides = pubspecs.values .where( (pubspec) => !_root.dependencyOverrides.containsKey(pubspec.name), ) .toList(); - var sdkConstraints = {}; + final sdkConstraints = {}; for (var pubspec in nonOverrides) { pubspec.sdkConstraints.forEach((identifier, constraint) { sdkConstraints[identifier] = constraint.effectiveConstraint @@ -111,7 +111,7 @@ class SolveResult { /// /// This includes packages that were added or removed. Set get changedPackages { - var changed = packages + final changed = packages .where((id) => _previousLockFile.packages[id.name] != id) .map((id) => id.name) .toSet(); diff --git a/lib/src/solver/term.dart b/lib/src/solver/term.dart index ac20cdc38..787511e60 100644 --- a/lib/src/solver/term.dart +++ b/lib/src/solver/term.dart @@ -51,7 +51,7 @@ class Term { ); } - var otherConstraint = other.constraint; + final otherConstraint = other.constraint; if (other.isPositive) { if (isPositive) { // foo from hosted is disjoint with foo from git @@ -127,8 +127,8 @@ class Term { if (_compatiblePackage(other.package)) { if (isPositive != other.isPositive) { // foo ^1.0.0 ∩ not foo ^1.5.0 → foo >=1.0.0 <1.5.0 - var positive = isPositive ? this : other; - var negative = isPositive ? other : this; + final positive = isPositive ? this : other; + final negative = isPositive ? other : this; return _nonEmptyTerm( positive.constraint.difference(negative.constraint), true, diff --git a/lib/src/solver/version_solver.dart b/lib/src/solver/version_solver.dart index 3f12427ca..7a007a714 100644 --- a/lib/src/solver/version_solver.dart +++ b/lib/src/solver/version_solver.dart @@ -142,10 +142,10 @@ class VersionSolver { /// /// [unit propagation]: https://github.com/dart-lang/pub/tree/master/doc/solver.md#unit-propagation void _propagate(String package) { - var changed = {package}; + final changed = {package}; while (changed.isNotEmpty) { - var package = changed.first; + final package = changed.first; changed.remove(package); // Iterate in reverse because conflict resolution tends to produce more @@ -153,14 +153,14 @@ class VersionSolver { // we can derive stronger assignments sooner and more eagerly find // conflicts. for (var incompatibility in _incompatibilities[package]!.reversed) { - var result = _propagateIncompatibility(incompatibility); + final result = _propagateIncompatibility(incompatibility); if (result == #conflict) { // If [incompatibility] is satisfied by [_solution], we use // [_resolveConflict] to determine the root cause of the conflict as a // new incompatibility. It also backjumps to a point in [_solution] // where that incompatibility will allow us to derive new assignments // that avoid the conflict. - var rootCause = _resolveConflict(incompatibility); + final rootCause = _resolveConflict(incompatibility); // Backjumping erases all the assignments we did at the previous // decision level, so we clear [changed] and refill it with the @@ -192,8 +192,8 @@ class VersionSolver { Term? unsatisfied; for (var i = 0; i < incompatibility.terms.length; i++) { - var term = incompatibility.terms[i]; - var relation = _solution.relation(term); + final term = incompatibility.terms[i]; + final relation = _solution.relation(term); if (relation == SetRelation.disjoint) { // If [term] is already contradicted by [_solution], then @@ -265,7 +265,7 @@ class VersionSolver { var previousSatisfierLevel = 1; for (var term in incompatibility.terms) { - var satisfier = _solution.satisfier(term); + final satisfier = _solution.satisfier(term); if (mostRecentSatisfier == null) { mostRecentTerm = term; mostRecentSatisfier = satisfier; @@ -314,7 +314,7 @@ class VersionSolver { // true (that is, we know for sure no solution will satisfy the // incompatibility) while also approximating the intuitive notion of the // "root cause" of the conflict. - var newTerms = [ + final newTerms = [ for (var term in incompatibility.terms) if (term != mostRecentTerm) term, for (var term in mostRecentSatisfier.cause!.terms) @@ -341,8 +341,8 @@ class VersionSolver { ); newIncompatibility = true; - var partially = difference == null ? '' : ' partially'; - var bang = log.red('!'); + final partially = difference == null ? '' : ' partially'; + final bang = log.red('!'); _log('$bang $mostRecentTerm is$partially satisfied by ' '$mostRecentSatisfier'); _log('$bang which is caused by "${mostRecentSatisfier.cause}"'); @@ -358,7 +358,7 @@ class VersionSolver { /// propagated by [_propagate], or `null` indicating that version solving is /// complete and a solution has been found. Future _choosePackageVersion() async { - var unsatisfied = _solution.unsatisfied.toList(); + final unsatisfied = _solution.unsatisfied.toList(); if (unsatisfied.isEmpty) return null; // If we require a package from an unknown source, add an incompatibility @@ -376,7 +376,7 @@ class VersionSolver { /// Prefer packages with as few remaining versions as possible, so that if a /// conflict is necessary it's forced quickly. - var package = await minByAsync(unsatisfied, (PackageRange package) async { + final package = await minByAsync(unsatisfied, (PackageRange package) async { return await _packageLister(package).countVersions(package.constraint); }); if (package == null) { @@ -458,8 +458,8 @@ class VersionSolver { /// Creates a [SolveResult] from the decisions in [_solution]. Future _result() async { - var decisions = _solution.decisions.toList(); - var pubspecs = {}; + final decisions = _solution.decisions.toList(); + final pubspecs = {}; for (var id in decisions) { if (id.isRoot) { pubspecs[id.name] = _rootPackages[id.name]!.pubspec; @@ -490,7 +490,7 @@ class VersionSolver { Future>> _getAvailableVersions( List packages, ) async { - var availableVersions = >{}; + final availableVersions = >{}; for (var package in packages) { // If the version list was never requested, use versions from cached // version listings if the package is "hosted". @@ -517,7 +517,7 @@ class VersionSolver { /// Returns the package lister for [package], creating it if necessary. PackageLister _packageLister(PackageRange package) { - var ref = package.toRef(); + final ref = package.toRef(); return _packageListers.putIfAbsent(ref, () { if (ref.isRoot) { return PackageLister.root( @@ -568,7 +568,7 @@ class VersionSolver { // non-hosted packages, since they don't support multiple versions and thus // can't be downgraded. if (_type == SolveType.downgrade) { - var locked = _lockFile.packages[package]; + final locked = _lockFile.packages[package]; if (locked != null && !locked.source.hasMultipleVersions) return locked; } @@ -584,7 +584,7 @@ class VersionSolver { /// `pubspec.lock` or pinned in `dependency_overrides`. Version? _getAllowedRetracted(String? package) { if (_dependencyOverrides.containsKey(package)) { - var range = _dependencyOverrides[package]!; + final range = _dependencyOverrides[package]!; if (range.constraint is Version) { // We have a pinned dependency. return range.constraint as Version?; diff --git a/lib/src/source/cached.dart b/lib/src/source/cached.dart index 478ecee93..a83f96d64 100644 --- a/lib/src/source/cached.dart +++ b/lib/src/source/cached.dart @@ -27,7 +27,7 @@ abstract class CachedSource extends Source { /// Otherwise, defers to the subclass. @override Future doDescribe(PackageId id, SystemCache cache) async { - var packageDir = getDirectoryInCache(id, cache); + final packageDir = getDirectoryInCache(id, cache); if (fileExists(p.join(packageDir, 'pubspec.yaml'))) { return Pubspec.load( packageDir, diff --git a/lib/src/source/git.dart b/lib/src/source/git.dart index 783dc4803..917eb759b 100644 --- a/lib/src/source/git.dart +++ b/lib/src/source/git.dart @@ -101,7 +101,7 @@ class GitSource extends CachedSource { 'key.'); } - var ref = description['ref']; + final ref = description['ref']; if (ref is! String?) { throw FormatException("The 'ref' field of the description must be a " 'string.'); @@ -235,8 +235,8 @@ class GitSource extends CachedSource { ); return await _pool.withResource(() async { await _ensureRepoCache(description, cache); - var path = _repoCachePath(description, cache); - var revision = await _firstRevision(path, description.ref); + final path = _repoCachePath(description, cache); + final revision = await _firstRevision(path, description.ref); final resolvedDescription = ResolvedGitDescription(description, revision); return Pubspec.parse( @@ -295,9 +295,9 @@ class GitSource extends CachedSource { } return await _pool.withResource(() async { await _ensureRepoCache(description, cache); - var path = _repoCachePath(description, cache); - var revision = await _firstRevision(path, description.ref); - var pubspec = await _describeUncached(ref, revision, cache); + final path = _repoCachePath(description, cache); + final revision = await _firstRevision(path, description.ref); + final pubspec = await _describeUncached(ref, revision, cache); return [ PackageId( @@ -386,7 +386,7 @@ class GitSource extends CachedSource { didUpdate |= await _ensureRevision(description, resolvedRef, cache); - var revisionCachePath = _revisionCachePath(id, cache); + final revisionCachePath = _revisionCachePath(id, cache); final path = description.path; await _revisionCacheClones.putIfAbsent(revisionCachePath, () async { if (!entryExists(revisionCachePath)) { @@ -433,7 +433,7 @@ class GitSource extends CachedSource { final result = []; - var packages = listDir(rootDir) + final packages = listDir(rootDir) .where((entry) => dirExists(p.join(entry, '.git'))) .expand((revisionCachePath) { return _readPackageList(revisionCachePath).map((relative) { @@ -441,7 +441,7 @@ class GitSource extends CachedSource { // repository, ignore it. if (!dirExists(revisionCachePath)) return null; - var packageDir = p.join(revisionCachePath, relative); + final packageDir = p.join(revisionCachePath, relative); try { return Package.load( packageDir, @@ -449,7 +449,7 @@ class GitSource extends CachedSource { ); } catch (error, stackTrace) { log.error('Failed to load package', error, stackTrace); - var name = p.basename(revisionCachePath).split('-').first; + final name = p.basename(revisionCachePath).split('-').first; result.add( RepairResult(name, Version.none, this, success: false), ); @@ -508,7 +508,7 @@ class GitSource extends CachedSource { String revision, SystemCache cache, ) async { - var path = _repoCachePath(description, cache); + final path = _repoCachePath(description, cache); if (_updatedRepos.contains(path)) return false; await _deleteGitRepoIfInvalid(path); @@ -534,7 +534,7 @@ class GitSource extends CachedSource { GitDescription description, SystemCache cache, ) async { - var path = _repoCachePath(description, cache); + final path = _repoCachePath(description, cache); if (_updatedRepos.contains(path)) return false; await _deleteGitRepoIfInvalid(path); @@ -554,7 +554,7 @@ class GitSource extends CachedSource { GitDescription description, SystemCache cache, ) async { - var path = _repoCachePath(description, cache); + final path = _repoCachePath(description, cache); assert(!_updatedRepos.contains(path)); try { await _cloneViaTemp(description.url, path, cache, mirror: true); @@ -575,7 +575,7 @@ class GitSource extends CachedSource { GitDescription description, SystemCache cache, ) async { - var path = _repoCachePath(description, cache); + final path = _repoCachePath(description, cache); if (_updatedRepos.contains(path)) return false; await git.run([_gitDirArg(path), 'fetch'], workingDir: path); _updatedRepos.add(path); @@ -614,7 +614,7 @@ class GitSource extends CachedSource { /// /// Returns `true` if it had to update anything. bool _updatePackageList(String revisionCachePath, String path) { - var packages = _readPackageList(revisionCachePath); + final packages = _readPackageList(revisionCachePath); if (packages.contains(path)) return false; _writePackageList(revisionCachePath, packages..add(path)); @@ -623,7 +623,7 @@ class GitSource extends CachedSource { /// Returns the list of packages in [revisionCachePath]. List _readPackageList(String revisionCachePath) { - var path = _packageListPath(revisionCachePath); + final path = _packageListPath(revisionCachePath); // If there's no package list file, this cache was created by an older // version of pub where pubspecs were only allowed at the root of the @@ -682,7 +682,7 @@ class GitSource extends CachedSource { // Git on Windows does not seem to automatically create the destination // directory. ensureDir(to); - var args = ['clone', if (mirror) '--mirror', from, to]; + final args = ['clone', if (mirror) '--mirror', from, to]; await git.run(args); } diff --git a/lib/src/source/hosted.dart b/lib/src/source/hosted.dart index f3def3b13..693a4e94a 100644 --- a/lib/src/source/hosted.dart +++ b/lib/src/source/hosted.dart @@ -396,7 +396,7 @@ class HostedSource extends CachedSource { if (pubspecData is! Map) { throw FormatException('pubspec must be a map'); } - var pubspec = Pubspec.fromMap( + final pubspec = Pubspec.fromMap( pubspecData, cache.sources, expectedName: ref.name, @@ -647,7 +647,7 @@ class HostedSource extends CachedSource { throw FormatException('summary must be a String'); } - var aliasIDs = []; + final aliasIDs = []; final aliases = advisory['aliases']; if (aliases is! List) { throw FormatException('aliases must be a list'); @@ -828,7 +828,7 @@ class HostedSource extends CachedSource { // Too old according to internal timestamp - delete. tryDeleteEntry(cachePath); } else { - var res = _versionInfoFromPackageListing( + final res = _versionInfoFromPackageListing( cachedDoc, ref, Uri.file(cachePath), @@ -1213,7 +1213,7 @@ class HostedSource extends CachedSource { } final rootDir = cache.rootDirForSource(this); - var dir = _urlToDirectory(description.url); + final dir = _urlToDirectory(description.url); return p.join(rootDir, dir, '${id.name}-${id.version}'); } @@ -1229,7 +1229,7 @@ class HostedSource extends CachedSource { } final rootDir = cache.rootDir; - var serverDir = _urlToDirectory(description.url); + final serverDir = _urlToDirectory(description.url); return p.join( rootDir, 'hosted-hashes', @@ -1274,7 +1274,7 @@ class HostedSource extends CachedSource { } final results = []; - var packages = []; + final packages = []; for (var entry in listDir(serverDir)) { try { packages.add( @@ -1310,7 +1310,7 @@ class HostedSource extends CachedSource { ..addAll( await Future.wait( packages.map((package) async { - var id = PackageId( + final id = PackageId( package.name, package.version, ResolvedHostedDescription( @@ -1348,7 +1348,7 @@ class HostedSource extends CachedSource { /// Returns the best-guess package ID for [basename], which should be a /// subdirectory in a hosted cache. PackageId _idForBasename(String basename, String url) { - var components = split1(basename, '-'); + final components = split1(basename, '-'); var version = Version.none; if (components.length > 1) { try { @@ -1366,7 +1366,7 @@ class HostedSource extends CachedSource { } bool _looksLikePackageDir(String path) { - var components = split1(p.basename(path), '-'); + final components = split1(p.basename(path), '-'); if (components.length < 2) return false; try { Version.parse(components.last); @@ -1381,7 +1381,7 @@ class HostedSource extends CachedSource { @override List getCachedPackages(SystemCache cache) { final root = cache.rootDirForSource(HostedSource.instance); - var cacheDir = + final cacheDir = p.join(root, _urlToDirectory(HostedSource.instance.defaultUrl)); if (!dirExists(cacheDir)) return []; @@ -1455,8 +1455,8 @@ class HostedSource extends CachedSource { // Download and extract the archive to a temp directory. return await withTempDir((tempDirForArchive) async { - var fileName = '$packageName-$version.tar.gz'; - var archivePath = p.join(tempDirForArchive, fileName); + final fileName = '$packageName-$version.tar.gz'; + final archivePath = p.join(tempDirForArchive, fileName); Stream> validateSha256( Stream> stream, @@ -1530,7 +1530,7 @@ See $contentHashesDocumentationUrl. _throwFriendlyError(error, stackTrace, id.name, description.url); } - var tempDir = cache.createTempDir(); + final tempDir = cache.createTempDir(); try { try { await extractTarGz(readBinaryFileAsStream(archivePath), tempDir); @@ -1576,7 +1576,7 @@ See $contentHashesDocumentationUrl. // of the cache. late final Uint8List contentHash; - var tempDir = cache.createTempDir(); + final tempDir = cache.createTempDir(); final PackageId id; try { try { @@ -1885,8 +1885,9 @@ String _urlToDirectory(String hostedUrl) { // Don't include the scheme for HTTPS URLs. This makes the directory names // nice for the default and most recommended scheme. We also don't include // it for localhost URLs, since they're always known to be HTTP. - var localhost = match[2] == null ? '' : 'localhost'; - var scheme = match[1] == 'https://' || localhost.isNotEmpty ? '' : match[1]; + final localhost = match[2] == null ? '' : 'localhost'; + final scheme = + match[1] == 'https://' || localhost.isNotEmpty ? '' : match[1]; return '$scheme$localhost'; }); return replace( @@ -1905,9 +1906,9 @@ String _urlToDirectory(String hostedUrl) { /// "https" for all others. String _directoryToUrl(String directory) { // Decode the pseudo-URL-encoded characters. - var chars = '<>:"\\/|?*%'; + const chars = '<>:"\\/|?*%'; for (var i = 0; i < chars.length; i++) { - var c = chars.substring(i, i + 1); + final c = chars.substring(i, i + 1); directory = directory.replaceAll('%${c.codeUnitAt(0)}', c); } @@ -1917,7 +1918,7 @@ String _directoryToUrl(String directory) { } // Otherwise, default to http for localhost and https for everything else. - var scheme = + final scheme = isLoopback(directory.replaceAll(RegExp(':.*'), '')) ? 'http' : 'https'; return Uri.parse('$scheme://$directory').toString(); } diff --git a/lib/src/source/path.dart b/lib/src/source/path.dart index e0451ef8f..3e2cc7b6e 100644 --- a/lib/src/source/path.dart +++ b/lib/src/source/path.dart @@ -69,10 +69,10 @@ class PathSource extends Source { if (description is! String) { throw FormatException('The description must be a path string.'); } - var dir = description; + final dir = description; // Resolve the path relative to the containing file path, and remember // whether the original path was relative or absolute. - var isRelative = p.isRelative(dir); + final isRelative = p.isRelative(dir); if (containingDescription is PathDescription) { return PackageRef( @@ -199,8 +199,8 @@ class PathSource extends Source { } // There's only one package ID for a given path. We just need to find the // version. - var pubspec = _loadPubspec(ref, cache); - var id = PackageId( + final pubspec = _loadPubspec(ref, cache); + final id = PackageId( ref.name, pubspec.version, ResolvedPathDescription(description), @@ -219,7 +219,7 @@ class PathSource extends Source { if (description is! PathDescription) { throw ArgumentError('Wrong source'); } - var dir = _validatePath(ref.name, description); + final dir = _validatePath(ref.name, description); return Pubspec.load( dir, cache.sources, diff --git a/lib/src/source/sdk.dart b/lib/src/source/sdk.dart index 24cb65859..aa78e865e 100644 --- a/lib/src/source/sdk.dart +++ b/lib/src/source/sdk.dart @@ -67,8 +67,8 @@ class SdkSource extends Source { if (description is! SdkDescription) { throw ArgumentError('Wrong source'); } - var pubspec = _loadPubspec(ref, cache); - var id = PackageId( + final pubspec = _loadPubspec(ref, cache); + final id = PackageId( ref.name, pubspec.version, ResolvedSdkDescription(description), @@ -90,7 +90,7 @@ class SdkSource extends Source { /// Throws a [PackageNotFoundException] if [ref]'s SDK is unavailable or /// doesn't contain the package. Pubspec _loadPubspec(PackageRef ref, SystemCache cache) { - var pubspec = Pubspec.load( + final pubspec = Pubspec.load( _verifiedPackagePath(ref), cache.sources, expectedName: ref.name, @@ -99,7 +99,7 @@ class SdkSource extends Source { /// Validate that there are no non-sdk dependencies if the SDK does not /// allow them. - if (ref.description case SdkDescription description) { + if (ref.description case final SdkDescription description) { if (sdks[description.sdk] case Sdk(allowsNonSdkDepsInSdkPackages: false)) { for (var dep in pubspec.dependencies.entries) { @@ -126,8 +126,8 @@ class SdkSource extends Source { if (description is! SdkDescription) { throw ArgumentError('Wrong source'); } - var sdkName = description.sdk; - var sdk = sdks[sdkName]; + final sdkName = description.sdk; + final sdk = sdks[sdkName]; if (sdk == null) { throw PackageNotFoundException('unknown SDK "$sdkName"'); } else if (!sdk.isAvailable) { @@ -137,7 +137,7 @@ class SdkSource extends Source { ); } - var path = sdk.packagePath(ref.name); + final path = sdk.packagePath(ref.name); if (path != null) return path; throw PackageNotFoundException( diff --git a/lib/src/system_cache.dart b/lib/src/system_cache.dart index b98bbb902..468a18a20 100644 --- a/lib/src/system_cache.dart +++ b/lib/src/system_cache.dart @@ -125,7 +125,7 @@ Consider setting the `PUB_CACHE` variable manually. /// system temp directory to ensure that it's on the same volume as the pub /// system cache so that it can move the directory from it. String createTempDir() { - var temp = ensureDir(tempDir); + final temp = ensureDir(tempDir); return io.createTempDir(temp, 'dir'); } @@ -147,7 +147,7 @@ Consider setting the `PUB_CACHE` variable manually. /// Throws a [DataException] if the pubspec's version doesn't match [id]'s /// version. Future describe(PackageId id) async { - var pubspec = cachedPubspecs[id] ??= await id.source.doDescribe(id, this); + final pubspec = cachedPubspecs[id] ??= await id.source.doDescribe(id, this); if (pubspec.version != id.version) { throw PackageNotFoundException( 'the pubspec for $id has version ${pubspec.version}', diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 2912b5f52..758f3e444 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -132,7 +132,7 @@ Future captureErrors( Future Function() callback, { bool captureStackChains = false, }) { - var completer = Completer(); + final completer = Completer(); void wrappedCallback() { Future.sync(callback) .then(completer.complete) @@ -259,7 +259,7 @@ bool isLoopback(String host) { /// Returns a list containing the sorted elements of [iter]. List ordered>(Iterable iter) { - var list = iter.toList(); + final list = iter.toList(); list.sort(); return list; } @@ -271,7 +271,7 @@ List ordered>(Iterable iter) { /// and only if that path's basename is in [files]. Set createFileFilter(Iterable files) { return files.expand((file) { - var result = ['/$file']; + final result = ['/$file']; if (Platform.isWindows) result.add('\\$file'); return result; }).toSet(); @@ -284,7 +284,7 @@ Set createFileFilter(Iterable files) { /// and only if one of that path's components is in [dirs]. Set createDirectoryFilter(Iterable dirs) { return dirs.expand((dir) { - var result = ['/$dir/']; + final result = ['/$dir/']; if (Platform.isWindows) { result ..add('/$dir\\') @@ -316,7 +316,7 @@ Future minByAsync( ) async { int? minIndex; T? minOrderBy; - var valuesList = values.toList(); + final valuesList = values.toList(); final orderByResults = await Future.wait(values.map(orderBy)); for (var i = 0; i < orderByResults.length; i++) { final elementOrderBy = orderByResults[i]; @@ -361,7 +361,7 @@ Future foldAsync( /// Replace each instance of [matcher] in [source] with the return value of /// [fn]. String replace(String source, Pattern matcher, String Function(Match) fn) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); var start = 0; for (var match in matcher.allMatches(source)) { buffer.write(source.substring(start, match.start)); @@ -395,7 +395,7 @@ List splitLines(String text) => List split1(String toSplit, String pattern) { if (toSplit.isEmpty) return []; - var index = toSplit.indexOf(pattern); + final index = toSplit.indexOf(pattern); if (index == -1) return [toSplit]; return [ toSplit.substring(0, index), @@ -406,12 +406,12 @@ List split1(String toSplit, String pattern) { /// Convert a URL query string (or `application/x-www-form-urlencoded` body) /// into a [Map] from parameter names to values. Map queryToMap(String queryList) { - var map = {}; + final map = {}; for (var pair in queryList.split('&')) { - var split = split1(pair, '='); + final split = split1(pair, '='); if (split.isEmpty) continue; - var key = _urlDecode(split[0]); - var value = split.length > 1 ? _urlDecode(split[1]) : ''; + final key = _urlDecode(split[0]); + final value = split.length > 1 ? _urlDecode(split[1]) : ''; map[key] = value; } return map; @@ -419,15 +419,15 @@ Map queryToMap(String queryList) { /// Returns a human-friendly representation of [duration]. String niceDuration(Duration duration) { - var hasMinutes = duration.inMinutes > 0; - var result = hasMinutes ? '${duration.inMinutes}:' : ''; + final hasMinutes = duration.inMinutes > 0; + final result = hasMinutes ? '${duration.inMinutes}:' : ''; - var s = duration.inSeconds % 60; - var ms = duration.inMilliseconds % 1000; + final s = duration.inSeconds % 60; + final ms = duration.inMilliseconds % 1000; // If we're using verbose logging, be more verbose but more accurate when // reporting timing information. - var msString = log.verbosity.isLevelVisible(log.Level.fine) + final msString = log.verbosity.isLevelVisible(log.Level.fine) ? _padLeft(ms.toString(), 3, '0') : (ms ~/ 100).toString(); @@ -498,7 +498,7 @@ String prefixLines(String text, {String prefix = '| ', String? firstPrefix}) { return lines.map((line) => '$prefix$line').join('\n'); } - var firstLine = '$firstPrefix${lines.first}'; + final firstLine = '$firstPrefix${lines.first}'; lines = lines.skip(1).map((line) => '$prefix$line').toList(); lines.insert(0, firstLine); return lines.join('\n'); @@ -513,7 +513,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(Object? data) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); void stringify(bool isMapValue, String indent, Object? data) { // TODO(nweiz): Serialize using the YAML library once it supports @@ -527,7 +527,7 @@ String yamlToString(Object? data) { } // Sort the keys. This minimizes deltas in diffs. - var keys = data.keys.toList(); + final keys = data.keys.toList(); keys.sort((a, b) => a.toString().compareTo(b.toString())); var first = true; @@ -589,14 +589,14 @@ Never dataError(String message) => throw DataException(message); /// /// If [bytes] is not provided, it is generated using `Random.secure`. String createUuid([List? bytes]) { - var rnd = math.Random.secure(); + final rnd = math.Random.secure(); // See http://www.cryptosys.net/pki/uuid-rfc4122.html for notes bytes ??= List.generate(16, (_) => rnd.nextInt(256)); bytes[6] = (bytes[6] & 0x0F) | 0x40; bytes[8] = (bytes[8] & 0x3f) | 0x80; - var chars = bytes + final chars = bytes .map((b) => b.toRadixString(16).padLeft(2, '0')) .join() .toUpperCase(); @@ -620,11 +620,11 @@ String wordWrap(String text, {String prefix = ''}) { } return text.split('\n').map((originalLine) { - var buffer = StringBuffer(); + final buffer = StringBuffer(); var lengthSoFar = 0; var firstLine = true; for (var word in originalLine.split(' ')) { - var wordLength = _withoutColors(word).length; + final wordLength = _withoutColors(word).length; if (wordLength > lineLength) { if (lengthSoFar != 0) buffer.writeln(); if (!firstLine) buffer.write(prefix); @@ -826,7 +826,7 @@ extension ExpectEntries on YamlList { /// not have a value of type [T]. List expectElements() => [ for (var node in nodes) - if (node.value case T value) + if (node.value case final T value) value else throw SourceSpanApplicationException( diff --git a/lib/src/validator.dart b/lib/src/validator.dart index 38b4024c7..c4fcdbc3e 100644 --- a/lib/src/validator.dart +++ b/lib/src/validator.dart @@ -92,7 +92,7 @@ abstract class Validator { firstSdkVersion = firstSdkVersion.nextPatch; } - var allowedSdks = VersionRange( + final allowedSdks = VersionRange( min: firstSdkVersion, includeMin: true, max: firstSdkVersion.isPreRelease @@ -138,7 +138,7 @@ abstract class Validator { required List warnings, required List errors, }) async { - var validators = [ + final validators = [ FileCaseValidator(), AnalyzeValidator(), GitignoreValidator(), diff --git a/lib/src/validator/changelog.dart b/lib/src/validator/changelog.dart index 65d7fdc1f..129c1fdbf 100644 --- a/lib/src/validator/changelog.dart +++ b/lib/src/validator/changelog.dart @@ -32,7 +32,7 @@ class ChangelogValidator extends Validator { 'See https://dart.dev/tools/pub/publishing#important-files.'); } - var bytes = readBinaryFile(changelog); + final bytes = readBinaryFile(changelog); String contents; try { diff --git a/lib/src/validator/compiled_dartdoc.dart b/lib/src/validator/compiled_dartdoc.dart index 27f1ebcdd..e74628e6a 100644 --- a/lib/src/validator/compiled_dartdoc.dart +++ b/lib/src/validator/compiled_dartdoc.dart @@ -16,10 +16,10 @@ class CompiledDartdocValidator extends Validator { return Future.sync(() { for (var entry in files) { if (p.basename(entry) != 'nav.json') continue; - var dir = p.dirname(entry); + final dir = p.dirname(entry); // Look for tell-tale Dartdoc output files all in the same directory. - var files = [ + final files = [ entry, p.join(dir, 'index.html'), p.join(dir, 'styles.css'), diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart index f6134e279..74233246b 100644 --- a/lib/src/validator/dependency.dart +++ b/lib/src/validator/dependency.dart @@ -25,8 +25,8 @@ class DependencyValidator extends Validator { /// Emit an error for dependencies from unknown SDKs or without appropriate /// constraints on the Dart SDK. void warnAboutSdkSource(PackageRange dep) { - var identifier = (dep.description as SdkDescription).sdk; - var sdk = sdks[identifier]; + final identifier = (dep.description as SdkDescription).sdk; + final sdk = sdks[identifier]; if (sdk == null) { errors.add('Unknown SDK "$identifier" for dependency "${dep.name}".'); return; @@ -37,7 +37,7 @@ class DependencyValidator extends Validator { Future warnAboutSource(PackageRange dep) async { List versions; try { - var ids = await cache.getVersions(cache.hosted.refFor(dep.name)); + final ids = await cache.getVersions(cache.hosted.refFor(dep.name)); versions = ids.map((id) => id.version).toList(); } on ApplicationException catch (_) { versions = []; @@ -54,7 +54,7 @@ class DependencyValidator extends Validator { } // Path sources are errors. Other sources are just warnings. - var messages = dep.source is PathSource ? errors : warnings; + final messages = dep.source is PathSource ? errors : warnings; messages.add('Don\'t depend on "${dep.name}" from the ${dep.source} ' 'source. Use the hosted source instead. For example:\n' @@ -87,7 +87,7 @@ class DependencyValidator extends Validator { void warnAboutNoConstraint(PackageRange dep) { var message = 'Your dependency on "${dep.name}" should have a version ' 'constraint.'; - var locked = context.entrypoint.lockFile.packages[dep.name]; + final locked = context.entrypoint.lockFile.packages[dep.name]; if (locked != null) { message = '$message For example:\n' '\n' @@ -117,7 +117,7 @@ class DependencyValidator extends Validator { void warnAboutNoConstraintLowerBound(PackageRange dep) { var message = 'Your dependency on "${dep.name}" should have a lower bound.'; - var locked = context.entrypoint.lockFile.packages[dep.name]; + final locked = context.entrypoint.lockFile.packages[dep.name]; if (locked != null) { String constraint; if (locked.version == (dep.constraint as VersionRange).max) { @@ -175,7 +175,7 @@ class DependencyValidator extends Validator { /// Validates all dependencies in [dependencies]. Future validateDependencies(Iterable dependencies) async { for (var dependency in dependencies) { - var constraint = dependency.constraint; + final constraint = dependency.constraint; if (dependency.name == 'flutter') { warnAboutFlutterSdk(dependency); } else if (dependency.source is SdkSource) { diff --git a/lib/src/validator/dependency_override.dart b/lib/src/validator/dependency_override.dart index 1b875ab2c..afdb34982 100644 --- a/lib/src/validator/dependency_override.dart +++ b/lib/src/validator/dependency_override.dart @@ -13,8 +13,8 @@ import '../validator.dart'; class DependencyOverrideValidator extends Validator { @override Future validate() { - var overridden = MapKeySet(package.dependencyOverrides); - var dev = MapKeySet(package.devDependencies); + final overridden = MapKeySet(package.dependencyOverrides); + final dev = MapKeySet(package.devDependencies); if (overridden.difference(dev).isNotEmpty) { final overridesFile = package.pubspec.dependencyOverridesFromOverridesFile ? package.pubspecOverridesPath diff --git a/lib/src/validator/directory.dart b/lib/src/validator/directory.dart index 63c39292b..71f559886 100644 --- a/lib/src/validator/directory.dart +++ b/lib/src/validator/directory.dart @@ -36,7 +36,7 @@ class DirectoryValidator extends Validator { final dirName = p.basename(dir); if (_pluralNames.contains(dirName)) { // Cut off the "s" - var singularName = dirName.substring(0, dirName.length - 1); + final singularName = dirName.substring(0, dirName.length - 1); warnings.add('Rename the top-level "$dirName" directory to ' '"$singularName".\n' 'The Pub layout convention is to use singular directory ' diff --git a/lib/src/validator/executable.dart b/lib/src/validator/executable.dart index ff178c860..2f29cc2b9 100644 --- a/lib/src/validator/executable.dart +++ b/lib/src/validator/executable.dart @@ -17,7 +17,7 @@ class ExecutableValidator extends Validator { filesBeneath('bin', recursive: false).map(package.relative); package.pubspec.executables.forEach((executable, script) { - var scriptPath = p.join('bin', '$script.dart'); + final scriptPath = p.join('bin', '$script.dart'); if (binFiles.contains(scriptPath)) return; warnings.add('Your pubspec.yaml lists an executable "$executable" that ' diff --git a/lib/src/validator/gitignore.dart b/lib/src/validator/gitignore.dart index 6afb25d0a..ff82e67b5 100644 --- a/lib/src/validator/gitignore.dart +++ b/lib/src/validator/gitignore.dart @@ -60,7 +60,7 @@ class GitignoreValidator extends Validator { final unignoredByGitignore = Ignore.listFiles( beneath: beneath, listDir: (dir) { - var contents = Directory(resolve(dir)).listSync(); + final contents = Directory(resolve(dir)).listSync(); return contents .where((e) => !(linkExists(e.path) && dirExists(e.path))) .map( diff --git a/lib/src/validator/name.dart b/lib/src/validator/name.dart index e0b7feecd..20c2a8019 100644 --- a/lib/src/validator/name.dart +++ b/lib/src/validator/name.dart @@ -17,10 +17,10 @@ class NameValidator extends Validator { return Future.sync(() { _checkName(package.name); - var libraries = _libraries(files); + final libraries = _libraries(files); if (libraries.length == 1) { - var libName = p.basenameWithoutExtension(libraries[0]); + final libName = p.basenameWithoutExtension(libraries[0]); if (libName == package.name) return; warnings.add('The name of "${libraries[0]}", "$libName", should match ' 'the name of the package, "${package.name}".\n' @@ -32,7 +32,7 @@ class NameValidator extends Validator { /// Returns a list of all libraries in the current package as paths relative /// to the package's root directory. List _libraries(List files) { - var libDir = package.path('lib'); + final libDir = package.path('lib'); return filesBeneath('lib', recursive: true) .map((file) => p.relative(file, from: p.dirname(libDir))) .where( @@ -63,7 +63,7 @@ class NameValidator extends Validator { } String _unCamelCase(String source) { - var builder = StringBuffer(); + final builder = StringBuffer(); var lastMatchEnd = 0; for (var match in RegExp(r'[a-z]([A-Z])').allMatches(source)) { builder diff --git a/lib/src/validator/pubspec_field.dart b/lib/src/validator/pubspec_field.dart index 385fbd5ec..1bab65d31 100644 --- a/lib/src/validator/pubspec_field.dart +++ b/lib/src/validator/pubspec_field.dart @@ -40,7 +40,7 @@ class PubspecFieldValidator extends Validator { /// Adds an error if [field] doesn't exist or isn't a string. void _validateFieldIsString(String field) { - var value = package.pubspec.fields[field]; + final value = package.pubspec.fields[field]; if (value == null) { errors.add('Your pubspec.yaml is missing a "$field" field.'); } else if (value is! String) { @@ -51,7 +51,7 @@ class PubspecFieldValidator extends Validator { /// Adds an error if the URL for [field] is invalid. void _validateFieldUrl(String field) { - var url = package.pubspec.fields[field]; + final url = package.pubspec.fields[field]; if (url == null) return; if (url is! String) { @@ -60,7 +60,7 @@ class PubspecFieldValidator extends Validator { return; } - var goodScheme = RegExp(r'^https?:'); + final goodScheme = RegExp(r'^https?:'); if (!goodScheme.hasMatch(url)) { errors.add('Your pubspec.yaml\'s "$field" field must be an "http:" or ' '"https:" URL, but it was "$url".'); diff --git a/lib/src/validator/readme.dart b/lib/src/validator/readme.dart index 360423254..fbcc7c5ff 100644 --- a/lib/src/validator/readme.dart +++ b/lib/src/validator/readme.dart @@ -42,7 +42,7 @@ class ReadmeValidator extends Validator { 'See https://dart.dev/tools/pub/publishing#important-files.'); } - var bytes = readBinaryFile(readme); + final bytes = readBinaryFile(readme); try { // utf8.decode doesn't allow invalid UTF-8. utf8.decode(bytes); diff --git a/lib/src/validator/size.dart b/lib/src/validator/size.dart index fac5e1637..b25a84286 100644 --- a/lib/src/validator/size.dart +++ b/lib/src/validator/size.dart @@ -15,11 +15,11 @@ class SizeValidator extends Validator { @override Future validate() async { if (packageSize <= _maxSize) return; - var sizeInMb = (packageSize / (1 << 20)).toStringAsPrecision(4); + final sizeInMb = (packageSize / (1 << 20)).toStringAsPrecision(4); // Current implementation of Package.listFiles skips hidden files - var ignoreExists = fileExists(package.path('.gitignore')); + final ignoreExists = fileExists(package.path('.gitignore')); - var hint = StringBuffer(''' + final hint = StringBuffer(''' Your package is $sizeInMb MB. Consider the impact large downloads can have on the package consumer.'''); diff --git a/lib/src/validator/strict_dependencies.dart b/lib/src/validator/strict_dependencies.dart index ea0e36f9f..0bf338550 100644 --- a/lib/src/validator/strict_dependencies.dart +++ b/lib/src/validator/strict_dependencies.dart @@ -28,7 +28,7 @@ class StrictDependenciesValidator extends Validator { for (var file in files) { List directives; - var contents = readTextFile(file); + final contents = readTextFile(file); try { directives = analysisContextManager.parseImportsAndExports(file); } on AnalyzerErrorGroup catch (e, s) { @@ -63,8 +63,8 @@ class StrictDependenciesValidator extends Validator { @override Future validate() async { - var dependencies = package.dependencies.keys.toSet()..add(package.name); - var devDependencies = MapKeySet(package.devDependencies); + final dependencies = package.dependencies.keys.toSet()..add(package.name); + final devDependencies = MapKeySet(package.devDependencies); _validateLibBin(dependencies, devDependencies); _validateBenchmarkTestTool(dependencies, devDependencies); } @@ -89,7 +89,7 @@ class StrictDependenciesValidator extends Validator { /// Validates that no Dart files in `benchmark/`, `test/` or /// `tool/` have dependencies that aren't in [deps] or [devDeps]. void _validateBenchmarkTestTool(Set deps, Set devDeps) { - var directories = ['benchmark', 'test', 'tool']; + final directories = ['benchmark', 'test', 'tool']; for (var usage in _usagesBeneath(directories)) { if (!deps.contains(usage.package) && !devDeps.contains(usage.package)) { warnings.add(usage.dependenciesMissingMessage()); @@ -161,7 +161,7 @@ class _Usage { /// Returns an error message saying the package should be in `dependencies`. String dependencyMisplaceMessage() { - var shortFile = p.split(p.relative(_file)).first; + final shortFile = p.split(p.relative(_file)).first; return _toMessage( '$package is in the `dev_dependencies` section of `pubspec.yaml`. ' 'Packages used in $shortFile/ must be declared in the `dependencies` ' diff --git a/test/ascii_tree_test.dart b/test/ascii_tree_test.dart index 7c1eb9b2b..018875b64 100644 --- a/test/ascii_tree_test.dart +++ b/test/ascii_tree_test.dart @@ -62,7 +62,7 @@ void main() { file('path.dart', bytes(100)), ]), ]).create(); - var files = Package.load( + final files = Package.load( path(appPath), loadPubspec: Pubspec.loadRootWithSources((name) => throw UnimplementedError()), @@ -76,7 +76,7 @@ void main() { }); testWithGolden('tree.fromMap a complex example', colors: true, (ctx) { - var map = { + final map = { '.gitignore': {}, 'README.md': {}, 'TODO': {}, diff --git a/test/cache/repair/git_test.dart b/test/cache/repair/git_test.dart index 04176ab24..cadfcf827 100644 --- a/test/cache/repair/git_test.dart +++ b/test/cache/repair/git_test.dart @@ -36,8 +36,8 @@ void main() { test('reinstalls previously cached git packages', () async { // Find the cached foo packages for each revision. - var gitCacheDir = p.join(d.sandbox, cachePath, 'git'); - var fooDirs = listDir(gitCacheDir) + final gitCacheDir = p.join(d.sandbox, cachePath, 'git'); + final fooDirs = listDir(gitCacheDir) .where((dir) => p.basename(dir).startsWith('foo-')) .toList(); @@ -56,8 +56,8 @@ void main() { ); // The missing libraries should have been replaced. - var fooLibs = fooDirs.map((dir) { - var fooDirName = p.basename(dir); + final fooLibs = fooDirs.map((dir) { + final fooDirName = p.basename(dir); return d.dir(fooDirName, [ d.dir('lib', [d.file('foo.dart', 'main() => "foo";')]), ]); @@ -67,8 +67,8 @@ void main() { }); test('deletes packages without pubspecs', () async { - var gitCacheDir = p.join(d.sandbox, cachePath, 'git'); - var fooDirs = listDir(gitCacheDir) + final gitCacheDir = p.join(d.sandbox, cachePath, 'git'); + final fooDirs = listDir(gitCacheDir) .where((dir) => p.basename(dir).startsWith('foo-')) .toList(); @@ -97,8 +97,8 @@ void main() { }); test('deletes packages with invalid pubspecs', () async { - var gitCacheDir = p.join(d.sandbox, cachePath, 'git'); - var fooDirs = listDir(gitCacheDir) + final gitCacheDir = p.join(d.sandbox, cachePath, 'git'); + final fooDirs = listDir(gitCacheDir) .where((dir) => p.basename(dir).startsWith('foo-')) .toList(); @@ -152,8 +152,8 @@ void main() { test('reinstalls previously cached git packages', () async { // Find the cached foo packages for each revision. - var gitCacheDir = p.join(d.sandbox, cachePath, 'git'); - var fooDirs = listDir(gitCacheDir) + final gitCacheDir = p.join(d.sandbox, cachePath, 'git'); + final fooDirs = listDir(gitCacheDir) .where((dir) => p.basename(dir).startsWith('foo-')) .toList(); @@ -172,8 +172,8 @@ void main() { ); // The missing libraries should have been replaced. - var fooLibs = fooDirs.map((dir) { - var fooDirName = p.basename(dir); + final fooLibs = fooDirs.map((dir) { + final fooDirName = p.basename(dir); return d.dir(fooDirName, [ d.dir('subdir', [ d.dir('lib', [d.file('sub.dart', 'main() => "sub";')]), @@ -185,8 +185,8 @@ void main() { }); test('deletes packages without pubspecs', () async { - var gitCacheDir = p.join(d.sandbox, cachePath, 'git'); - var fooDirs = listDir(gitCacheDir) + final gitCacheDir = p.join(d.sandbox, cachePath, 'git'); + final fooDirs = listDir(gitCacheDir) .where((dir) => p.basename(dir).startsWith('foo-')) .toList(); diff --git a/test/cache/repair/handles_failure_test.dart b/test/cache/repair/handles_failure_test.dart index d59fab70e..14847eec6 100644 --- a/test/cache/repair/handles_failure_test.dart +++ b/test/cache/repair/handles_failure_test.dart @@ -36,7 +36,7 @@ void main() { ]).create(); // Repair them. - var pub = await startPub(args: ['cache', 'repair']); + final pub = await startPub(args: ['cache', 'repair']); expect(pub.stderr, emits(startsWith('Failed to repair foo 1.2.4. Error:'))); expect( diff --git a/test/cache/repair/recompiles_snapshots_test.dart b/test/cache/repair/recompiles_snapshots_test.dart index 46588a392..167675c98 100644 --- a/test/cache/repair/recompiles_snapshots_test.dart +++ b/test/cache/repair/recompiles_snapshots_test.dart @@ -38,7 +38,7 @@ void main() { Reactivated 1 package.''', ); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); expect(pub.stdout, emits('ok')); await pub.shouldExit(); }); diff --git a/test/dependency_override_test.dart b/test/dependency_override_test.dart index 8c6001732..7c3d8e13b 100644 --- a/test/dependency_override_test.dart +++ b/test/dependency_override_test.dart @@ -121,7 +121,7 @@ void main() { }), ]).create(); - var bazPath = p.join('..', 'baz'); + final bazPath = p.join('..', 'baz'); await runPub( args: [command.name], diff --git a/test/descriptor.dart b/test/descriptor.dart index 7749e92f5..7984f40c5 100644 --- a/test/descriptor.dart +++ b/test/descriptor.dart @@ -92,7 +92,7 @@ Descriptor rawPubspec(Map contents) => /// Describes a file named `pubspec.yaml` for an application package with the /// given [dependencies]. Descriptor appPubspec({Map? dependencies, Map? extras}) { - var map = { + final map = { 'name': 'myapp', ...?extras, }; @@ -115,7 +115,7 @@ FileDescriptor libPubspec( Map? extras, bool resolutionWorkspace = false, }) { - var map = packageMap(name, version, deps, devDeps); + final map = packageMap(name, version, deps, devDeps); if (resolutionWorkspace && sdk == null) { sdk = '3.5.0'; } @@ -197,11 +197,11 @@ Descriptor cacheDir( int? port, bool includePubspecs = false, }) { - var contents = []; + final contents = []; packages.forEach((name, versions) { if (versions is! List) versions = [versions]; for (var version in versions) { - var packageContents = [libDir(name, '$name $version')]; + final packageContents = [libDir(name, '$name $version')]; if (includePubspecs) { packageContents.add(libPubspec(name, version as String)); } diff --git a/test/descriptor/git.dart b/test/descriptor/git.dart index 0b3542390..addde7379 100644 --- a/test/descriptor/git.dart +++ b/test/descriptor/git.dart @@ -45,7 +45,7 @@ class GitRepoDescriptor extends DirectoryDescriptor { /// /// [parent] defaults to [sandbox]. Future revParse(String ref, [String? parent]) async { - var output = await _runGit(['rev-parse', ref], parent); + final output = await _runGit(['rev-parse', ref], parent); return output[0]; } @@ -57,7 +57,7 @@ class GitRepoDescriptor extends DirectoryDescriptor { Future> _runGit(List args, String? parent) { // Explicitly specify the committer information. Git needs this to commit // and we don't want to rely on the buildbots having this already set up. - var environment = { + final environment = { 'GIT_AUTHOR_NAME': 'Pub Test', 'GIT_AUTHOR_EMAIL': 'pub@dartlang.org', 'GIT_COMMITTER_NAME': 'Pub Test', diff --git a/test/descriptor/tar.dart b/test/descriptor/tar.dart index a02f97d1b..f8570e548 100644 --- a/test/descriptor/tar.dart +++ b/test/descriptor/tar.dart @@ -25,16 +25,16 @@ class TarFileDescriptor extends FileDescriptor { return withTempDir((tempDir) async { await Future.wait(contents.map((entry) => entry.create(tempDir))); - var createdContents = listDir( + final createdContents = listDir( tempDir, recursive: true, includeHidden: true, includeDirs: false, ); - var bytes = + final bytes = await createTarGz(createdContents, baseDir: tempDir).toBytes(); - var file = p.join(parent ?? sandbox, name); + final file = p.join(parent ?? sandbox, name); _writeBinaryFile(file, bytes); return file; }); diff --git a/test/descriptor/yaml.dart b/test/descriptor/yaml.dart index 6afb9d05b..a9b4d778f 100644 --- a/test/descriptor/yaml.dart +++ b/test/descriptor/yaml.dart @@ -28,12 +28,12 @@ class YamlDescriptor extends FileDescriptor { @override Future validate([String? parent]) async { - var fullPath = p.join(parent ?? sandbox, name); + final fullPath = p.join(parent ?? sandbox, name); if (!await File(fullPath).exists()) { fail("File not found: '$fullPath'."); } - var bytes = await File(fullPath).readAsBytes(); + final bytes = await File(fullPath).readAsBytes(); final actualContentsText = utf8.decode(bytes); final actual = loadYaml(actualContentsText); diff --git a/test/downgrade/doesnt_change_git_dependencies_test.dart b/test/downgrade/doesnt_change_git_dependencies_test.dart index 33ab4edb9..9d832d896 100644 --- a/test/downgrade/doesnt_change_git_dependencies_test.dart +++ b/test/downgrade/doesnt_change_git_dependencies_test.dart @@ -24,7 +24,7 @@ void main() { await pubGet(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await d.git( 'foo.git', diff --git a/test/embedding/ensure_pubspec_resolved.dart b/test/embedding/ensure_pubspec_resolved.dart index b025a7676..75d4d2dc3 100644 --- a/test/embedding/ensure_pubspec_resolved.dart +++ b/test/embedding/ensure_pubspec_resolved.dart @@ -542,11 +542,11 @@ Future _noImplicitPubGet({ expect(output, isNot(contains('Resolving dependencies'))); // If pub determines that everything is up-to-date, it should set the // mtimes to indicate that. - var pubspecModified = + final pubspecModified = File(p.join(d.sandbox, 'myapp/pubspec.yaml')).lastModifiedSync(); - var lockFileModified = + final lockFileModified = File(p.join(d.sandbox, 'myapp/pubspec.lock')).lastModifiedSync(); - var packageConfigModified = + final packageConfigModified = File(p.join(d.sandbox, 'myapp/.dart_tool/package_config.json')) .lastModifiedSync(); diff --git a/test/error_group_test.dart b/test/error_group_test.dart index ec673bbbc..92ee749ed 100644 --- a/test/error_group_test.dart +++ b/test/error_group_test.dart @@ -241,7 +241,7 @@ void main() { }); test('should pass through values from the stream', () { - var iter = StreamIterator(stream); + final iter = StreamIterator(stream); iter.moveNext().then((hasNext) { expect(hasNext, isTrue); expect(iter.current, equals(1)); @@ -407,7 +407,7 @@ void main() { test( "shouldn't throw a top-level exception if a stream receives an error " 'after the other listened stream completes', () { - var signal = Completer(); + final signal = Completer(); expect( stream1.toList().whenComplete(signal.complete), completion(equals(['value1', 'value2'])), @@ -429,7 +429,7 @@ void main() { test( "shouldn't throw a top-level exception if an error is signaled after " 'one listened stream completes', () { - var signal = Completer(); + final signal = Completer(); expect( stream1.toList().whenComplete(signal.complete), completion(equals(['value1', 'value2'])), @@ -511,7 +511,7 @@ void main() { test( "shouldn't throw a top-level exception if the future receives an " 'error after the listened stream completes', () { - var signal = Completer(); + final signal = Completer(); expect( stream.toList().whenComplete(signal.complete), completion(equals(['value1', 'value2'])), diff --git a/test/get/git/check_out_and_upgrade_test.dart b/test/get/git/check_out_and_upgrade_test.dart index c654e2ba9..32a320b1a 100644 --- a/test/get/git/check_out_and_upgrade_test.dart +++ b/test/get/git/check_out_and_upgrade_test.dart @@ -40,7 +40,7 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await d.git( 'foo.git', diff --git a/test/get/git/check_out_branch_test.dart b/test/get/git/check_out_branch_test.dart index 62d5706a8..b98ac8ea2 100644 --- a/test/get/git/check_out_branch_test.dart +++ b/test/get/git/check_out_branch_test.dart @@ -11,7 +11,7 @@ void main() { test('checks out a package at a specific branch from Git', () async { ensureGit(); - var repo = d.git( + final repo = d.git( 'foo.git', [d.libDir('foo', 'foo 1'), d.libPubspec('foo', '1.0.0')], ); diff --git a/test/get/git/check_out_revision_test.dart b/test/get/git/check_out_revision_test.dart index 61646cd75..591f25766 100644 --- a/test/get/git/check_out_revision_test.dart +++ b/test/get/git/check_out_revision_test.dart @@ -11,12 +11,12 @@ void main() { test('checks out a package at a specific revision from Git', () async { ensureGit(); - var repo = d.git( + final repo = d.git( 'foo.git', [d.libDir('foo', 'foo 1'), d.libPubspec('foo', '1.0.0')], ); await repo.create(); - var commit = await repo.revParse('HEAD'); + final commit = await repo.revParse('HEAD'); await d.git( 'foo.git', diff --git a/test/get/git/check_out_unfetched_revision_of_cached_repo_test.dart b/test/get/git/check_out_unfetched_revision_of_cached_repo_test.dart index 7e56b8684..30bc0fd1c 100644 --- a/test/get/git/check_out_unfetched_revision_of_cached_repo_test.dart +++ b/test/get/git/check_out_unfetched_revision_of_cached_repo_test.dart @@ -32,7 +32,7 @@ void main() { await pubGet(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); // Switch to a new cache. renameInSandbox(cachePath, '$cachePath.old'); @@ -46,7 +46,7 @@ void main() { await pubUpgrade(output: contains('Changed 1 dependency!')); // Switch back to the old cache. - var cacheDir = p.join(d.sandbox, cachePath); + final cacheDir = p.join(d.sandbox, cachePath); deleteEntry(cacheDir); renameInSandbox('$cachePath.old', cacheDir); diff --git a/test/get/git/clean_invalid_git_repo_cache_test.dart b/test/get/git/clean_invalid_git_repo_cache_test.dart index a6aa58ecd..42a7a3c1f 100644 --- a/test/get/git/clean_invalid_git_repo_cache_test.dart +++ b/test/get/git/clean_invalid_git_repo_cache_test.dart @@ -54,7 +54,7 @@ void main() { test('Clean-up invalid git repo cache at a specific branch', () async { ensureGit(); - var repo = + final repo = d.git('foo.git', [d.libDir('foo'), d.libPubspec('foo', '1.0.0')]); await repo.create(); await repo.runGit(['branch', 'old']); @@ -84,10 +84,10 @@ void main() { test('Clean-up invalid git repo cache at a specific commit', () async { ensureGit(); - var repo = + final repo = d.git('foo.git', [d.libDir('foo'), d.libPubspec('foo', '1.0.0')]); await repo.create(); - var commit = await repo.revParse('HEAD'); + final commit = await repo.revParse('HEAD'); await d.appDir( dependencies: { diff --git a/test/get/git/doesnt_fetch_if_nothing_changes_test.dart b/test/get/git/doesnt_fetch_if_nothing_changes_test.dart index f2212e46f..a2580274c 100644 --- a/test/get/git/doesnt_fetch_if_nothing_changes_test.dart +++ b/test/get/git/doesnt_fetch_if_nothing_changes_test.dart @@ -28,7 +28,7 @@ void main() { await pubGet(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); // Delete the repo. This will cause "pub get" to fail if it tries to // re-fetch. diff --git a/test/get/git/lock_version_test.dart b/test/get/git/lock_version_test.dart index 003e0807f..3fa063e5b 100644 --- a/test/get/git/lock_version_test.dart +++ b/test/get/git/lock_version_test.dart @@ -36,7 +36,7 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); // Delete the package spec to simulate a new checkout of the application. deleteEntry(p.join(d.sandbox, packageConfigFilePath)); diff --git a/test/get/git/locked_revision_without_repo_test.dart b/test/get/git/locked_revision_without_repo_test.dart index 6fe9ef18c..b6b2503e3 100644 --- a/test/get/git/locked_revision_without_repo_test.dart +++ b/test/get/git/locked_revision_without_repo_test.dart @@ -38,7 +38,7 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); // Delete the package spec and the cache to simulate a brand new checkout // of the application. diff --git a/test/get/git/path_test.dart b/test/get/git/path_test.dart index eae19ed81..957bdebb7 100644 --- a/test/get/git/path_test.dart +++ b/test/get/git/path_test.dart @@ -17,7 +17,7 @@ void main() { test('depends on a package in a subdirectory', () async { ensureGit(); - var repo = d.git('foo.git', [ + final repo = d.git('foo.git', [ d.dir('subdir', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')]), ]); await repo.create(); @@ -52,7 +52,7 @@ void main() { test('depends on a package in a deep subdirectory', () async { ensureGit(); - var repo = d.git('foo.git', [ + final repo = d.git('foo.git', [ d.dir('sub', [ d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')]), ]), @@ -192,7 +192,7 @@ void main() { () async { ensureGit(); - var repo = d.git('foo.git', [ + final repo = d.git('foo.git', [ d.dir('sub', [ d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')]), ]), @@ -246,7 +246,7 @@ void main() { test('depends on multiple packages in subdirectories', () async { ensureGit(); - var repo = d.git('foo.git', [ + final repo = d.git('foo.git', [ d.dir( 'subdir1', [d.libPubspec('sub1', '1.0.0'), d.libDir('sub1', '1.0.0')], @@ -297,14 +297,14 @@ void main() { () async { ensureGit(); - var repo = d.git('foo.git', [ + final repo = d.git('foo.git', [ d.dir( 'subdir', [d.libPubspec('sub1', '1.0.0'), d.libDir('sub1', '1.0.0')], ), ]); await repo.create(); - var oldRevision = await repo.revParse('HEAD'); + final oldRevision = await repo.revParse('HEAD'); deleteEntry(p.join(d.sandbox, 'foo.git', 'subdir')); @@ -314,7 +314,7 @@ void main() { [d.libPubspec('sub2', '1.0.0'), d.libDir('sub2', '1.0.0')], ), ]).commit(); - var newRevision = await repo.revParse('HEAD'); + final newRevision = await repo.revParse('HEAD'); await d.appDir( dependencies: { diff --git a/test/get/git/stay_locked_if_compatible_test.dart b/test/get/git/stay_locked_if_compatible_test.dart index 3f52179d6..6bde0c2a8 100644 --- a/test/get/git/stay_locked_if_compatible_test.dart +++ b/test/get/git/stay_locked_if_compatible_test.dart @@ -26,7 +26,7 @@ void main() { await pubGet(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await d.git( 'foo.git', diff --git a/test/get/git/unlock_if_incompatible_test.dart b/test/get/git/unlock_if_incompatible_test.dart index 56a779c42..5bdbccdf6 100644 --- a/test/get/git/unlock_if_incompatible_test.dart +++ b/test/get/git/unlock_if_incompatible_test.dart @@ -35,7 +35,7 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await d.git( 'foo.git', diff --git a/test/get/hosted/get_test.dart b/test/get/hosted/get_test.dart index 60d7e2485..c45371e0f 100644 --- a/test/get/hosted/get_test.dart +++ b/test/get/hosted/get_test.dart @@ -102,7 +102,7 @@ void main() { // be accessed. (await servePackages()).serveErrors(); - var server = await startPackageServer(); + final server = await startPackageServer(); server.serve('foo', '1.2.3'); await d.appDir( @@ -124,7 +124,7 @@ void main() { test('recognizes and retries a package with a CRC32C checksum mismatch', () async { - var server = await startPackageServer(); + final server = await startPackageServer(); server.serve( 'foo', @@ -312,7 +312,7 @@ void main() { await pubGet(); - var packages = loadYaml( + final packages = loadYaml( readTextFile(p.join(d.sandbox, appPath, 'pubspec.lock')), )['packages']; expect( @@ -353,7 +353,7 @@ void main() { await pubGet(); - var packages = loadYaml( + final packages = loadYaml( readTextFile(p.join(d.sandbox, appPath, 'pubspec.lock')), )['packages']; expect( diff --git a/test/get/path/absolute_symlink_test.dart b/test/get/path/absolute_symlink_test.dart index ba42da372..1f373eab7 100644 --- a/test/get/path/absolute_symlink_test.dart +++ b/test/get/path/absolute_symlink_test.dart @@ -15,7 +15,7 @@ void main() { await d .dir('foo', [d.libDir('foo'), d.libPubspec('foo', '0.0.1')]).create(); - var fooPath = d.path('foo'); + final fooPath = d.path('foo'); await d.dir(appPath, [ d.appPubspec( dependencies: { diff --git a/test/get/path/no_pubspec_test.dart b/test/get/path/no_pubspec_test.dart index 364990719..076db44b6 100644 --- a/test/get/path/no_pubspec_test.dart +++ b/test/get/path/no_pubspec_test.dart @@ -13,7 +13,7 @@ void main() { test('path dependency to non-package directory', () async { // Make an empty directory. await d.dir('foo').create(); - var fooPath = p.join(d.sandbox, 'foo'); + final fooPath = p.join(d.sandbox, 'foo'); await d.dir(appPath, [ d.appPubspec( diff --git a/test/get/path/nonexistent_dir_test.dart b/test/get/path/nonexistent_dir_test.dart index 1990a1aff..df942ddc5 100644 --- a/test/get/path/nonexistent_dir_test.dart +++ b/test/get/path/nonexistent_dir_test.dart @@ -11,7 +11,7 @@ import '../../test_pub.dart'; void main() { test('path dependency to non-existent directory', () async { - var badPath = p.join(d.sandbox, 'bad_path'); + final badPath = p.join(d.sandbox, 'bad_path'); await d.dir(appPath, [ d.appPubspec( diff --git a/test/get/path/path_is_file_test.dart b/test/get/path/path_is_file_test.dart index 88eaceb5c..8fbae7807 100644 --- a/test/get/path/path_is_file_test.dart +++ b/test/get/path/path_is_file_test.dart @@ -15,7 +15,7 @@ void main() { .dir('foo', [d.libDir('foo'), d.libPubspec('foo', '0.0.1')]).create(); await d.file('dummy.txt', '').create(); - var dummyPath = p.join(d.sandbox, 'dummy.txt'); + final dummyPath = p.join(d.sandbox, 'dummy.txt'); await d.dir(appPath, [ d.appPubspec( diff --git a/test/get/path/relative_path_test.dart b/test/get/path/relative_path_test.dart index 4b379f970..1e46aa3fc 100644 --- a/test/get/path/relative_path_test.dart +++ b/test/get/path/relative_path_test.dart @@ -115,15 +115,15 @@ void main() { await pubGet(); - var lockfilePath = p.join(d.sandbox, appPath, 'pubspec.lock'); + final lockfilePath = p.join(d.sandbox, appPath, 'pubspec.lock'); final lockfileJson = loadYaml(File(lockfilePath).readAsStringSync()); expect( lockfileJson['packages']['foo']['description']['path'], '../foo', reason: 'Should use `/` as separator on all platforms', ); - var lockfile = LockFile.load(lockfilePath, SystemCache().sources); - var description = + final lockfile = LockFile.load(lockfilePath, SystemCache().sources); + final description = lockfile.packages['foo']!.description.description as PathDescription; expect(description.relative, isTrue); diff --git a/test/global/activate/activate_git_after_hosted_test.dart b/test/global/activate/activate_git_after_hosted_test.dart index 567f45d27..aa4689b0f 100644 --- a/test/global/activate/activate_git_after_hosted_test.dart +++ b/test/global/activate/activate_git_after_hosted_test.dart @@ -43,7 +43,7 @@ void main() { ); // Should now run the git one. - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('git')); await pub.shouldExit(); }); diff --git a/test/global/activate/activate_hosted_after_git_test.dart b/test/global/activate/activate_hosted_after_git_test.dart index ea71b687c..fcdff9686 100644 --- a/test/global/activate/activate_hosted_after_git_test.dart +++ b/test/global/activate/activate_hosted_after_git_test.dart @@ -38,7 +38,7 @@ void main() { ); // Should now run the hosted one. - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('hosted')); await pub.shouldExit(); }); diff --git a/test/global/activate/activate_hosted_after_path_test.dart b/test/global/activate/activate_hosted_after_path_test.dart index 8aef7be5f..8fe4a4963 100644 --- a/test/global/activate/activate_hosted_after_path_test.dart +++ b/test/global/activate/activate_hosted_after_path_test.dart @@ -27,7 +27,7 @@ void main() { await runPub(args: ['global', 'activate', '-spath', '../foo']); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub( args: ['global', 'activate', 'foo'], output: ''' @@ -41,7 +41,7 @@ void main() { ); // Should now run the hosted one. - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('hosted')); await pub.shouldExit(); }); diff --git a/test/global/activate/activate_hosted_twice_test.dart b/test/global/activate/activate_hosted_twice_test.dart index ce6cbc104..2d5eb9c62 100644 --- a/test/global/activate/activate_hosted_twice_test.dart +++ b/test/global/activate/activate_hosted_twice_test.dart @@ -44,7 +44,7 @@ To recompile executables, first run `dart pub global deactivate foo`. Activated foo 1.0.0.''', ); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('bar 1.0.0')); await pub.shouldExit(); @@ -70,7 +70,7 @@ Built foo:foo. Activated foo 1.0.0.''', ); - var pub2 = await pubRun(global: true, args: ['foo']); + final pub2 = await pubRun(global: true, args: ['foo']); expect(pub2.stdout, emits('bar 2.0.0')); await pub2.shouldExit(); }); diff --git a/test/global/activate/activate_path_after_hosted_test.dart b/test/global/activate/activate_path_after_hosted_test.dart index b6d95ca3d..ad0effea4 100644 --- a/test/global/activate/activate_path_after_hosted_test.dart +++ b/test/global/activate/activate_path_after_hosted_test.dart @@ -27,7 +27,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub( args: ['global', 'activate', '-spath', '../foo'], output: allOf([ @@ -37,7 +37,7 @@ void main() { ); // Should now run the path one. - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emitsThrough('path')); await pub.shouldExit(); }); diff --git a/test/global/activate/installs_dependencies_for_path_test.dart b/test/global/activate/installs_dependencies_for_path_test.dart index 7c9f11e74..556b6d224 100644 --- a/test/global/activate/installs_dependencies_for_path_test.dart +++ b/test/global/activate/installs_dependencies_for_path_test.dart @@ -18,7 +18,8 @@ void main() { d.dir('bin', [d.file('foo.dart', "main() => print('ok');")]), ]).create(); - var pub = await startPub(args: ['global', 'activate', '-spath', '../foo']); + final pub = + await startPub(args: ['global', 'activate', '-spath', '../foo']); expect(pub.stdout, emitsThrough('Resolving dependencies in `../foo`...')); expect(pub.stdout, emitsThrough(startsWith('Activated foo 0.0.0 at path'))); await pub.shouldExit(); diff --git a/test/global/activate/path_package_test.dart b/test/global/activate/path_package_test.dart index 0ec71d020..29162bd11 100644 --- a/test/global/activate/path_package_test.dart +++ b/test/global/activate/path_package_test.dart @@ -16,7 +16,7 @@ void main() { d.dir('bin', [d.file('foo.dart', "main() => print('ok');")]), ]).create(); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub( args: ['global', 'activate', '--source', 'path', '../foo'], output: endsWith('Activated foo 1.0.0 at path "$path".'), @@ -48,7 +48,7 @@ void main() { d.dir('lib', [d.file('bar.dart', "final value = 'ok';")]), ]).create(); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub( args: ['global', 'activate', '--source', 'path', '../foo'], output: endsWith('Activated foo 1.0.0 at path "$path".'), diff --git a/test/global/binstubs/binstub_runs_executable_test.dart b/test/global/binstubs/binstub_runs_executable_test.dart index 3e0fc911c..9e36701ef 100644 --- a/test/global/binstubs/binstub_runs_executable_test.dart +++ b/test/global/binstubs/binstub_runs_executable_test.dart @@ -29,7 +29,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var process = await TestProcess.start( + final process = await TestProcess.start( p.join(d.sandbox, cachePath, 'bin', binStubName('foo-script')), ['arg1', 'arg2'], environment: getEnvironment(), @@ -54,7 +54,7 @@ void main() { await runPub(args: ['global', 'activate', '-spath', '../foo']); - var process = await TestProcess.start( + final process = await TestProcess.start( p.join(d.sandbox, cachePath, 'bin', binStubName('foo-script')), ['arg1', 'arg2'], environment: getEnvironment(), diff --git a/test/global/binstubs/does_not_warn_if_on_path_test.dart b/test/global/binstubs/does_not_warn_if_on_path_test.dart index f3575c3eb..dbe665431 100644 --- a/test/global/binstubs/does_not_warn_if_on_path_test.dart +++ b/test/global/binstubs/does_not_warn_if_on_path_test.dart @@ -28,9 +28,9 @@ void main() { ); // Add the test's cache bin directory to the path. - var binDir = p.dirname(Platform.executable); - var separator = Platform.isWindows ? ';' : ':'; - var path = "${Platform.environment["PATH"]}$separator$binDir"; + final binDir = p.dirname(Platform.executable); + final separator = Platform.isWindows ? ';' : ':'; + final path = "${Platform.environment["PATH"]}$separator$binDir"; await runPub( args: ['global', 'activate', 'foo'], diff --git a/test/global/binstubs/missing_script_test.dart b/test/global/binstubs/missing_script_test.dart index 9dfd9784f..61915dc22 100644 --- a/test/global/binstubs/missing_script_test.dart +++ b/test/global/binstubs/missing_script_test.dart @@ -17,7 +17,8 @@ void main() { }), ]).create(); - var pub = await startPub(args: ['global', 'activate', '-spath', '../foo']); + final pub = + await startPub(args: ['global', 'activate', '-spath', '../foo']); expect( pub.stderr, diff --git a/test/global/binstubs/name_collision_test.dart b/test/global/binstubs/name_collision_test.dart index 1f811a708..7e1c33f86 100644 --- a/test/global/binstubs/name_collision_test.dart +++ b/test/global/binstubs/name_collision_test.dart @@ -27,7 +27,8 @@ void main() { await runPub(args: ['global', 'activate', '-spath', '../foo']); - var pub = await startPub(args: ['global', 'activate', '-spath', '../bar']); + final pub = + await startPub(args: ['global', 'activate', '-spath', '../bar']); expect(pub.stdout, emitsThrough('Installed executable bar.')); expect( pub.stderr, diff --git a/test/global/binstubs/name_collision_with_overwrite_test.dart b/test/global/binstubs/name_collision_with_overwrite_test.dart index 491256c7d..3588b2c2e 100644 --- a/test/global/binstubs/name_collision_with_overwrite_test.dart +++ b/test/global/binstubs/name_collision_with_overwrite_test.dart @@ -27,7 +27,7 @@ void main() { await runPub(args: ['global', 'activate', '-spath', '../foo']); - var pub = await startPub( + final pub = await startPub( args: ['global', 'activate', '-spath', '../bar', '--overwrite'], ); expect( diff --git a/test/global/binstubs/outdated_binstub_runs_pub_global_test.dart b/test/global/binstubs/outdated_binstub_runs_pub_global_test.dart index b86e42ac3..8325c1627 100644 --- a/test/global/binstubs/outdated_binstub_runs_pub_global_test.dart +++ b/test/global/binstubs/outdated_binstub_runs_pub_global_test.dart @@ -95,7 +95,7 @@ void main() { ]), ]).create(); - var process = await TestProcess.start( + final process = await TestProcess.start( p.join(d.sandbox, cachePath, 'bin', binStubName('foo-script')), ['arg1', 'arg2'], environment: getEnvironment(), diff --git a/test/global/binstubs/outdated_snapshot_test.dart b/test/global/binstubs/outdated_snapshot_test.dart index a4471acee..4511a0ad1 100644 --- a/test/global/binstubs/outdated_snapshot_test.dart +++ b/test/global/binstubs/outdated_snapshot_test.dart @@ -51,7 +51,7 @@ void main() { ), ); - var process = await TestProcess.start( + final process = await TestProcess.start( p.join(d.sandbox, cachePath, 'bin', binStubName('foo-script')), ['arg1', 'arg2'], environment: getEnvironment(), diff --git a/test/global/binstubs/runs_once_even_when_dart_is_batch_test.dart b/test/global/binstubs/runs_once_even_when_dart_is_batch_test.dart index 79d57d28c..777cc8439 100644 --- a/test/global/binstubs/runs_once_even_when_dart_is_batch_test.dart +++ b/test/global/binstubs/runs_once_even_when_dart_is_batch_test.dart @@ -38,7 +38,7 @@ ${Platform.resolvedExecutable} %* ], ).create(); - var process = await Process.run( + final process = await Process.run( p.join(d.sandbox, cachePath, 'bin', 'script.bat'), ['hi'], environment: { diff --git a/test/global/binstubs/unknown_explicit_executable_test.dart b/test/global/binstubs/unknown_explicit_executable_test.dart index 8f47678e3..b58dff512 100644 --- a/test/global/binstubs/unknown_explicit_executable_test.dart +++ b/test/global/binstubs/unknown_explicit_executable_test.dart @@ -18,7 +18,7 @@ void main() { d.dir('bin', [d.file('one.dart', "main() => print('ok');")]), ]).create(); - var pub = await startPub( + final pub = await startPub( args: [ 'global', 'activate', '--source', 'path', '../foo', // '-x', 'who', '-x', 'one', '--executable', 'wat', diff --git a/test/global/binstubs/utils.dart b/test/global/binstubs/utils.dart index 59a8df0af..bbd44a7bc 100644 --- a/test/global/binstubs/utils.dart +++ b/test/global/binstubs/utils.dart @@ -15,13 +15,13 @@ import '../../test_pub.dart'; /// The `pub`/`pub.bat` command on the PATH will be the one in tool/test-bin not /// the one from the sdk. Map getEnvironment() { - var binDir = p.dirname(Platform.resolvedExecutable); - var separator = Platform.isWindows ? ';' : ':'; - var pubBin = p.absolute('tool', 'test-bin'); - var path = + final binDir = p.dirname(Platform.resolvedExecutable); + final separator = Platform.isWindows ? ';' : ':'; + final pubBin = p.absolute('tool', 'test-bin'); + final path = "$pubBin$separator${Platform.environment["PATH"]}$separator$binDir"; - var environment = getPubTestEnvironment(); + final environment = getPubTestEnvironment(); environment['PATH'] = path; return environment; } diff --git a/test/global/deactivate/path_package_test.dart b/test/global/deactivate/path_package_test.dart index 655f2cd4a..78eebc034 100644 --- a/test/global/deactivate/path_package_test.dart +++ b/test/global/deactivate/path_package_test.dart @@ -18,7 +18,7 @@ void main() { await runPub(args: ['global', 'activate', '--source', 'path', '../foo']); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub( args: ['global', 'deactivate', 'foo'], output: 'Deactivated package foo 1.0.0 at path "$path".', diff --git a/test/global/list_test.dart b/test/global/list_test.dart index 6dca489e7..1f59243b3 100644 --- a/test/global/list_test.dart +++ b/test/global/list_test.dart @@ -44,7 +44,7 @@ void main() { await runPub(args: ['global', 'activate', '-spath', '../foo']); - var path = canonicalize(p.join(d.sandbox, 'foo')); + final path = canonicalize(p.join(d.sandbox, 'foo')); await runPub(args: ['global', 'list'], output: 'foo 1.0.0 at path "$path"'); }); diff --git a/test/global/run/implicit_executable_name_test.dart b/test/global/run/implicit_executable_name_test.dart index 323001617..96897769b 100644 --- a/test/global/run/implicit_executable_name_test.dart +++ b/test/global/run/implicit_executable_name_test.dart @@ -20,7 +20,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('foo')); await pub.shouldExit(); }); diff --git a/test/global/run/missing_path_package_test.dart b/test/global/run/missing_path_package_test.dart index dce42da1a..68aae227e 100644 --- a/test/global/run/missing_path_package_test.dart +++ b/test/global/run/missing_path_package_test.dart @@ -20,7 +20,7 @@ void main() { deleteEntry(p.join(d.sandbox, 'foo')); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect( pub.stderr, emits('The directory `${d.path('foo')}` does not exist.'), diff --git a/test/global/run/nonexistent_script_test.dart b/test/global/run/nonexistent_script_test.dart index 515dbfb04..90e3fb050 100644 --- a/test/global/run/nonexistent_script_test.dart +++ b/test/global/run/nonexistent_script_test.dart @@ -21,7 +21,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); expect( pub.stderr, emits( diff --git a/test/global/run/package_api_test.dart b/test/global/run/package_api_test.dart index 2abb7f043..6d849c317 100644 --- a/test/global/run/package_api_test.dart +++ b/test/global/run/package_api_test.dart @@ -35,20 +35,20 @@ main() async { await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); - var packageConfigPath = p.join( + final packageConfigPath = p.join( d.sandbox, cachePath, 'global_packages/foo/.dart_tool/package_config.json', ); expect(pub.stdout, emits(p.toUri(packageConfigPath).toString())); - var fooResourcePath = + final fooResourcePath = p.join(globalServer.pathInCache('foo', '1.0.0'), 'lib/resource.txt'); expect(pub.stdout, emits(p.toUri(fooResourcePath).toString())); - var barResourcePath = + final barResourcePath = p.join(globalServer.pathInCache('bar', '1.0.0'), 'lib/resource.txt'); expect(pub.stdout, emits(p.toUri(barResourcePath).toString())); await pub.shouldExit(0); @@ -81,16 +81,16 @@ main() async { await runPub(args: ['global', 'activate', '-s', 'path', '.']); - var pub = await pubRun(global: true, args: ['myapp:script']); + final pub = await pubRun(global: true, args: ['myapp:script']); - var packageConfigPath = + final packageConfigPath = p.join(d.sandbox, 'myapp/.dart_tool/package_config.json'); expect(pub.stdout, emitsThrough(p.toUri(packageConfigPath).toString())); - var myappResourcePath = p.join(d.sandbox, 'myapp/lib/resource.txt'); + final myappResourcePath = p.join(d.sandbox, 'myapp/lib/resource.txt'); expect(pub.stdout, emits(p.toUri(myappResourcePath).toString())); - var fooResourcePath = p.join(d.sandbox, 'foo/lib/resource.txt'); + final fooResourcePath = p.join(d.sandbox, 'foo/lib/resource.txt'); expect(pub.stdout, emits(p.toUri(fooResourcePath).toString())); await pub.shouldExit(0); }); diff --git a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart index d71fb10d4..f16d55a5b 100644 --- a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart +++ b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart @@ -41,7 +41,7 @@ void main() { 'script.dart-$versionSuffix.snapshot', ), ); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); // In the real world this would just print "hello!", but since we collect // all output we see the precompilation messages as well. expect(pub.stdout, emits('Building package executable...')); diff --git a/test/global/run/reflects_changes_to_local_package_test.dart b/test/global/run/reflects_changes_to_local_package_test.dart index 0cc276a03..476d7d98a 100644 --- a/test/global/run/reflects_changes_to_local_package_test.dart +++ b/test/global/run/reflects_changes_to_local_package_test.dart @@ -18,7 +18,7 @@ void main() { await d.file('foo/bin/foo.dart', "main() => print('changed');").create(); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emitsThrough('changed')); await pub.shouldExit(); }); diff --git a/test/global/run/runs_git_script_test.dart b/test/global/run/runs_git_script_test.dart index 8bdfef726..4ff42690c 100644 --- a/test/global/run/runs_git_script_test.dart +++ b/test/global/run/runs_git_script_test.dart @@ -18,7 +18,7 @@ void main() { await runPub(args: ['global', 'activate', '-sgit', '../foo.git']); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emits('ok')); await pub.shouldExit(); }); diff --git a/test/global/run/runs_path_script_test.dart b/test/global/run/runs_path_script_test.dart index 29220f34a..fdd6fe840 100644 --- a/test/global/run/runs_path_script_test.dart +++ b/test/global/run/runs_path_script_test.dart @@ -16,7 +16,7 @@ void main() { await runPub(args: ['global', 'activate', '--source', 'path', '../foo']); - var pub = await pubRun(global: true, args: ['foo']); + final pub = await pubRun(global: true, args: ['foo']); expect(pub.stdout, emitsThrough('ok')); await pub.shouldExit(); }); diff --git a/test/global/run/runs_script_in_checked_mode_test.dart b/test/global/run/runs_script_in_checked_mode_test.dart index 10cb45411..4d080c22f 100644 --- a/test/global/run/runs_script_in_checked_mode_test.dart +++ b/test/global/run/runs_script_in_checked_mode_test.dart @@ -20,7 +20,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var pub = + final pub = await pubRun(global: true, args: ['--enable-asserts', 'foo:script']); expect(pub.stderr, emitsThrough(contains('Failed assertion'))); await pub.shouldExit(255); diff --git a/test/global/run/runs_script_in_unchecked_mode_test.dart b/test/global/run/runs_script_in_unchecked_mode_test.dart index 0451a7103..d781e3ea3 100644 --- a/test/global/run/runs_script_in_unchecked_mode_test.dart +++ b/test/global/run/runs_script_in_unchecked_mode_test.dart @@ -27,7 +27,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); expect(pub.stdout, emits('no checks')); await pub.shouldExit(); }); diff --git a/test/global/run/runs_script_test.dart b/test/global/run/runs_script_test.dart index c8c8e379d..abd8d28f6 100644 --- a/test/global/run/runs_script_test.dart +++ b/test/global/run/runs_script_test.dart @@ -20,7 +20,7 @@ void main() { await runPub(args: ['global', 'activate', 'foo']); - var pub = await pubRun(global: true, args: ['foo:script']); + final pub = await pubRun(global: true, args: ['foo:script']); expect(pub.stdout, emits('ok')); await pub.shouldExit(); }); diff --git a/test/hosted/metadata_test.dart b/test/hosted/metadata_test.dart index 1bc3cc040..736fe0d2d 100644 --- a/test/hosted/metadata_test.dart +++ b/test/hosted/metadata_test.dart @@ -87,7 +87,7 @@ void main() { }); test("doesn't send metadata headers to a foreign server", () async { - var server = await startPackageServer() + final server = await startPackageServer() ..serve('foo', '1.0.0'); await d.appDir( diff --git a/test/hosted/version_negotiation_test.dart b/test/hosted/version_negotiation_test.dart index 858f1a3aa..fea2ef5b0 100644 --- a/test/hosted/version_negotiation_test.dart +++ b/test/hosted/version_negotiation_test.dart @@ -48,7 +48,7 @@ void main() { }, ).create(); - var pub = await startPub(args: [command.name]); + final pub = await startPub(args: [command.name]); globalServer.expect( 'GET', diff --git a/test/ignore_test.dart b/test/ignore_test.dart index dd09cd52d..7627cd1a0 100644 --- a/test/ignore_test.dart +++ b/test/ignore_test.dart @@ -98,7 +98,7 @@ void main() { for (final c in testData) { c.paths.forEach((path, expected) { - var ignoreCase = c.ignoreCase; + final ignoreCase = c.ignoreCase; if (ignoreCase == null) { testIgnorePath(c, path, expected, false); testIgnorePath(c, path, expected, true); @@ -197,7 +197,7 @@ void main() { for (final c in testData) { c.paths.forEach((path, expected) { - var ignoreCase = c.ignoreCase; + final ignoreCase = c.ignoreCase; if (ignoreCase == null) { testIgnorePath(c, path, expected, false); testIgnorePath(c, path, expected, true); diff --git a/test/io_test.dart b/test/io_test.dart index e20628654..4877ebb94 100644 --- a/test/io_test.dart +++ b/test/io_test.dart @@ -91,7 +91,7 @@ void main() { test("doesn't ignore hidden files above the directory being listed", () { expect( withTempDir((temp) { - var dir = p.join(temp, '.foo', 'bar'); + final dir = p.join(temp, '.foo', 'bar'); ensureDir(dir); writeTextFile(p.join(dir, 'file1.txt'), ''); writeTextFile(p.join(dir, 'file2.txt'), ''); @@ -115,7 +115,7 @@ void main() { test('resolves a non-link', () { expect( _withCanonicalTempDir((temp) { - var filePath = p.join(temp, 'file'); + final filePath = p.join(temp, 'file'); writeTextFile(filePath, ''); expect(canonicalize(filePath), equals(filePath)); }), @@ -189,7 +189,7 @@ void main() { test('resolves a single-level horizontally recursive symlink', () { expect( _withCanonicalTempDir((temp) { - var linkPath = p.join(temp, 'foo'); + final linkPath = p.join(temp, 'foo'); createSymlink(linkPath, linkPath); expect(canonicalize(linkPath), equals(linkPath)); }), @@ -200,9 +200,9 @@ void main() { test('resolves a multi-level horizontally recursive symlink', () { expect( _withCanonicalTempDir((temp) { - var fooPath = p.join(temp, 'foo'); - var barPath = p.join(temp, 'bar'); - var bazPath = p.join(temp, 'baz'); + final fooPath = p.join(temp, 'foo'); + final barPath = p.join(temp, 'bar'); + final bazPath = p.join(temp, 'baz'); createSymlink(barPath, fooPath); createSymlink(bazPath, barPath); createSymlink(fooPath, bazPath); @@ -233,10 +233,10 @@ void main() { test('resolves multiple nested symlinks', () { expect( _withCanonicalTempDir((temp) { - var dir1 = p.join(temp, 'dir1'); - var dir2 = p.join(temp, 'dir2'); - var subdir1 = p.join(dir1, 'subdir1'); - var subdir2 = p.join(dir2, 'subdir2'); + final dir1 = p.join(temp, 'dir1'); + final dir2 = p.join(temp, 'dir2'); + final subdir1 = p.join(dir1, 'subdir1'); + final subdir2 = p.join(dir2, 'subdir2'); _createDir(dir2); _createDir(subdir2); createSymlink(dir2, dir1); @@ -253,9 +253,9 @@ void main() { test('resolves a nested vertical symlink', () { expect( _withCanonicalTempDir((temp) { - var dir1 = p.join(temp, 'dir1'); - var dir2 = p.join(temp, 'dir2'); - var subdir = p.join(dir1, 'subdir'); + final dir1 = p.join(temp, 'dir1'); + final dir2 = p.join(temp, 'dir2'); + final subdir = p.join(dir1, 'subdir'); _createDir(dir1); _createDir(dir2); createSymlink(dir2, subdir); @@ -271,8 +271,8 @@ void main() { test('resolves a vertically recursive symlink', () { expect( _withCanonicalTempDir((temp) { - var dir = p.join(temp, 'dir'); - var subdir = p.join(dir, 'subdir'); + final dir = p.join(temp, 'dir'); + final subdir = p.join(dir, 'subdir'); _createDir(dir); createSymlink(dir, subdir); expect( @@ -298,9 +298,9 @@ void main() { () { expect( _withCanonicalTempDir((temp) { - var dir = p.join(temp, 'dir'); - var linkdir = p.join(temp, 'linkdir'); - var linkfile = p.join(dir, 'link'); + final dir = p.join(temp, 'dir'); + final linkdir = p.join(temp, 'linkdir'); + final linkfile = p.join(dir, 'link'); _createDir(dir); createSymlink(dir, linkdir); createSymlink(p.join(linkdir, 'file'), linkfile); @@ -313,10 +313,10 @@ void main() { test('resolves a pair of pathologically-recursive symlinks', () { expect( _withCanonicalTempDir((temp) { - var foo = p.join(temp, 'foo'); - var subfoo = p.join(foo, 'subfoo'); - var bar = p.join(temp, 'bar'); - var subbar = p.join(bar, 'subbar'); + final foo = p.join(temp, 'foo'); + final subfoo = p.join(foo, 'subfoo'); + final bar = p.join(temp, 'bar'); + final subbar = p.join(bar, 'subbar'); createSymlink(subbar, foo); createSymlink(subfoo, bar); expect( @@ -627,7 +627,7 @@ void testExistencePredicate( test('returns $forFile for a file', () { expect( withTempDir((temp) { - var file = p.join(temp, 'test.txt'); + final file = p.join(temp, 'test.txt'); writeTextFile(file, 'contents'); expect(predicate(file), equals(forFile)); }), @@ -638,7 +638,7 @@ void testExistencePredicate( test('returns $forDirectory for a directory', () { expect( withTempDir((temp) { - var file = p.join(temp, 'dir'); + final file = p.join(temp, 'dir'); _createDir(file); expect(predicate(file), equals(forDirectory)); }), @@ -649,8 +649,8 @@ void testExistencePredicate( test('returns $forDirectorySymlink for a symlink to a directory', () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'dir'); - var symlinkPath = p.join(temp, 'linkdir'); + final targetPath = p.join(temp, 'dir'); + final symlinkPath = p.join(temp, 'linkdir'); _createDir(targetPath); createSymlink(targetPath, symlinkPath); expect(predicate(symlinkPath), equals(forDirectorySymlink)); @@ -664,9 +664,9 @@ void testExistencePredicate( 'a directory', () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'dir'); - var symlink1Path = p.join(temp, 'link1dir'); - var symlink2Path = p.join(temp, 'link2dir'); + final targetPath = p.join(temp, 'dir'); + final symlink1Path = p.join(temp, 'link1dir'); + final symlink2Path = p.join(temp, 'link2dir'); _createDir(targetPath); createSymlink(targetPath, symlink1Path); createSymlink(symlink1Path, symlink2Path); @@ -682,8 +682,8 @@ void testExistencePredicate( test('returns $forBrokenSymlink for a broken symlink', () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'dir'); - var symlinkPath = p.join(temp, 'linkdir'); + final targetPath = p.join(temp, 'dir'); + final symlinkPath = p.join(temp, 'linkdir'); _createDir(targetPath); createSymlink(targetPath, symlinkPath); deleteEntry(targetPath); @@ -697,9 +697,9 @@ void testExistencePredicate( () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'dir'); - var symlink1Path = p.join(temp, 'link1dir'); - var symlink2Path = p.join(temp, 'link2dir'); + final targetPath = p.join(temp, 'dir'); + final symlink1Path = p.join(temp, 'link1dir'); + final symlink2Path = p.join(temp, 'link2dir'); _createDir(targetPath); createSymlink(targetPath, symlink1Path); createSymlink(symlink1Path, symlink2Path); @@ -715,8 +715,8 @@ void testExistencePredicate( test('returns $forFileSymlink for a symlink to a file', () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'test.txt'); - var symlinkPath = p.join(temp, 'link.txt'); + final targetPath = p.join(temp, 'test.txt'); + final symlinkPath = p.join(temp, 'link.txt'); writeTextFile(targetPath, 'contents'); createSymlink(targetPath, symlinkPath); expect(predicate(symlinkPath), equals(forFileSymlink)); @@ -730,9 +730,9 @@ void testExistencePredicate( 'file', () { expect( withTempDir((temp) { - var targetPath = p.join(temp, 'test.txt'); - var symlink1Path = p.join(temp, 'link1.txt'); - var symlink2Path = p.join(temp, 'link2.txt'); + final targetPath = p.join(temp, 'test.txt'); + final symlink1Path = p.join(temp, 'link1.txt'); + final symlink2Path = p.join(temp, 'link2.txt'); writeTextFile(targetPath, 'contents'); createSymlink(targetPath, symlink1Path); createSymlink(symlink1Path, symlink2Path); diff --git a/test/lish/archives_and_uploads_a_package_test.dart b/test/lish/archives_and_uploads_a_package_test.dart index 2c3f917e8..cff6aedbb 100644 --- a/test/lish/archives_and_uploads_a_package_test.dart +++ b/test/lish/archives_and_uploads_a_package_test.dart @@ -19,7 +19,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); @@ -50,7 +50,7 @@ void main() { {'url': globalServer.url, 'token': 'access-token'}, ], }).create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); @@ -81,7 +81,7 @@ void main() { {'url': '${globalServer.url}/sub/folder', 'env': 'TOKEN'}, ], }).create(); - var pub = await startPublish( + final pub = await startPublish( globalServer, path: '/sub/folder', overrideDefaultHostedServer: false, @@ -114,7 +114,7 @@ void main() { test('with an empty Git submodule', () async { await d.git('empty').create(); - var repo = d.git(appPath, d.validPackage().contents); + final repo = d.git(appPath, d.validPackage().contents); await repo.create(); await repo.runGit([ @@ -134,7 +134,7 @@ void main() { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/cloud_storage_upload_doesnt_redirect_test.dart b/test/lish/cloud_storage_upload_doesnt_redirect_test.dart index 38f32cf6b..8aff97ca9 100644 --- a/test/lish/cloud_storage_upload_doesnt_redirect_test.dart +++ b/test/lish/cloud_storage_upload_doesnt_redirect_test.dart @@ -14,7 +14,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/cloud_storage_upload_provides_an_error_test.dart b/test/lish/cloud_storage_upload_provides_an_error_test.dart index 431e43380..be0ba9f1f 100644 --- a/test/lish/cloud_storage_upload_provides_an_error_test.dart +++ b/test/lish/cloud_storage_upload_provides_an_error_test.dart @@ -14,7 +14,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/does_not_include_dot_file.dart b/test/lish/does_not_include_dot_file.dart index 7c9e6a435..8ddbcca07 100644 --- a/test/lish/does_not_include_dot_file.dart +++ b/test/lish/does_not_include_dot_file.dart @@ -31,7 +31,7 @@ void main() { test('Check if package doesn\'t include dot-files', () async { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/does_not_include_pubspec_overrides_file.dart b/test/lish/does_not_include_pubspec_overrides_file.dart index 6d5c67181..bd98a0545 100644 --- a/test/lish/does_not_include_pubspec_overrides_file.dart +++ b/test/lish/does_not_include_pubspec_overrides_file.dart @@ -32,7 +32,7 @@ void main() { test('Check if package doesn\'t include pubspec_overrides.yaml', () async { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/dry_run_package_validation_has_a_warning_test.dart b/test/lish/dry_run_package_validation_has_a_warning_test.dart index 358a98624..b8fa47677 100644 --- a/test/lish/dry_run_package_validation_has_a_warning_test.dart +++ b/test/lish/dry_run_package_validation_has_a_warning_test.dart @@ -14,7 +14,7 @@ void main() { (await servePackages()).serve('foo', '1.0.0'); await d.validPackage().create(); - var pkg = packageMap( + final pkg = packageMap( 'test_pkg', '1.0.0', null, @@ -24,7 +24,7 @@ void main() { pkg['dependencies'] = {'foo': 'any'}; await d.dir(appPath, [d.pubspec(pkg)]).create(); - var pub = await startPublish(globalServer, args: ['--dry-run']); + final pub = await startPublish(globalServer, args: ['--dry-run']); await pub.shouldExit(exit_codes.DATA); expect( diff --git a/test/lish/dry_run_package_validation_has_no_warnings_test.dart b/test/lish/dry_run_package_validation_has_no_warnings_test.dart index 30452205d..08c84e915 100644 --- a/test/lish/dry_run_package_validation_has_no_warnings_test.dart +++ b/test/lish/dry_run_package_validation_has_no_warnings_test.dart @@ -15,7 +15,7 @@ void main() { await d.validPackage().create(); await servePackages(); - var pub = await startPublish(globalServer, args: ['--dry-run']); + final pub = await startPublish(globalServer, args: ['--dry-run']); await pub.shouldExit(exit_codes.SUCCESS); expect(pub.stderr, emitsThrough('Package has 0 warnings.')); diff --git a/test/lish/force_does_not_publish_if_there_are_errors_test.dart b/test/lish/force_does_not_publish_if_there_are_errors_test.dart index d1cad32c9..65238744b 100644 --- a/test/lish/force_does_not_publish_if_there_are_errors_test.dart +++ b/test/lish/force_does_not_publish_if_there_are_errors_test.dart @@ -19,7 +19,7 @@ void main() { File(d.path(p.join(appPath, 'LICENSE'))).deleteSync(); await servePackages(); - var pub = await startPublish(globalServer, args: ['--force']); + final pub = await startPublish(globalServer, args: ['--force']); await pub.shouldExit(exit_codes.DATA); expect( diff --git a/test/lish/force_publishes_if_tests_are_no_warnings_or_errors_test.dart b/test/lish/force_publishes_if_tests_are_no_warnings_or_errors_test.dart index 7b0484eb1..ccc9958e2 100644 --- a/test/lish/force_publishes_if_tests_are_no_warnings_or_errors_test.dart +++ b/test/lish/force_publishes_if_tests_are_no_warnings_or_errors_test.dart @@ -17,7 +17,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer, args: ['--force']); + final pub = await startPublish(globalServer, args: ['--force']); handleUploadForm(globalServer); handleUpload(globalServer); diff --git a/test/lish/force_publishes_if_there_are_warnings_test.dart b/test/lish/force_publishes_if_there_are_warnings_test.dart index 2e6a1fb80..ceded0fd8 100644 --- a/test/lish/force_publishes_if_there_are_warnings_test.dart +++ b/test/lish/force_publishes_if_there_are_warnings_test.dart @@ -15,7 +15,7 @@ import 'utils.dart'; void main() { test('--force publishes if there are warnings', () async { await d.validPackage().create(); - var pkg = packageMap( + final pkg = packageMap( 'test_pkg', '1.0.0', null, @@ -28,7 +28,7 @@ void main() { (await servePackages()).serve('foo', '1.0.0'); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer, args: ['--force']); + final pub = await startPublish(globalServer, args: ['--force']); handleUploadForm(globalServer); handleUpload(globalServer); diff --git a/test/lish/many_files_test.dart b/test/lish/many_files_test.dart index 189731090..c9b4691b2 100644 --- a/test/lish/many_files_test.dart +++ b/test/lish/many_files_test.dart @@ -41,7 +41,7 @@ void main() { ).create(); await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); pub.stdin.writeln('y'); handleUploadForm(globalServer); handleUpload(globalServer); @@ -73,7 +73,7 @@ void main() { } else { // On POSIX, the maximum argument list length can be retrieved // automatically. - var result = Process.runSync('getconf', ['ARG_MAX']); + final result = Process.runSync('getconf', ['ARG_MAX']); if (result.exitCode != 0) { fail('getconf failed with exit code ${result.exitCode}:\n' '${result.stderr}'); @@ -82,25 +82,25 @@ void main() { argMax = int.parse(result.stdout as String); } - var appRoot = p.join(d.sandbox, appPath); + final appRoot = p.join(d.sandbox, appPath); // We'll make the filenames as long as possible to reduce the number of // files we have to create to hit the maximum. However, the tar process // uses relative paths, which means we can't count the root as part of the // length. - var lengthPerFile = _pathMax - appRoot.length; + final lengthPerFile = _pathMax - appRoot.length; // Create enough files to hit [argMax]. This may be a slight overestimate, // since other options are passed to the tar command line, but we don't // know how long those will be. - var filesToCreate = (argMax / lengthPerFile).ceil(); + final filesToCreate = (argMax / lengthPerFile).ceil(); for (var i = 0; i < filesToCreate; i++) { - var iString = i.toString(); + final iString = i.toString(); // The file name contains "x"s to make the path hit [_pathMax], // followed by a number to distinguish different files. - var fileName = + final fileName = 'x' * (_pathMax - appRoot.length - iString.length - 1) + iString; File(p.join(appRoot, fileName)).writeAsStringSync(''); @@ -108,7 +108,7 @@ void main() { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/package_creation_provides_a_malformed_error_test.dart b/test/lish/package_creation_provides_a_malformed_error_test.dart index 662f896b7..d2d6ef973 100644 --- a/test/lish/package_creation_provides_a_malformed_error_test.dart +++ b/test/lish/package_creation_provides_a_malformed_error_test.dart @@ -16,13 +16,13 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); handleUpload(globalServer); - var body = {'error': 'Your package was too boring.'}; + final body = {'error': 'Your package was too boring.'}; globalServer.expect('GET', '/create', (request) { return shelf.Response.notFound(jsonEncode(body)); }); diff --git a/test/lish/package_creation_provides_a_malformed_success_test.dart b/test/lish/package_creation_provides_a_malformed_success_test.dart index dc3791bad..048c980a0 100644 --- a/test/lish/package_creation_provides_a_malformed_success_test.dart +++ b/test/lish/package_creation_provides_a_malformed_success_test.dart @@ -16,13 +16,13 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); handleUpload(globalServer); - var body = {'success': 'Your package was awesome.'}; + final body = {'success': 'Your package was awesome.'}; globalServer.expect('GET', '/create', (request) { return shelf.Response.ok(jsonEncode(body)); }); diff --git a/test/lish/package_creation_provides_an_error_test.dart b/test/lish/package_creation_provides_an_error_test.dart index 564aa4210..313cb0dcd 100644 --- a/test/lish/package_creation_provides_an_error_test.dart +++ b/test/lish/package_creation_provides_an_error_test.dart @@ -16,7 +16,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/package_creation_provides_invalid_json_test.dart b/test/lish/package_creation_provides_invalid_json_test.dart index 9a7b93588..a4b2fe8df 100644 --- a/test/lish/package_creation_provides_invalid_json_test.dart +++ b/test/lish/package_creation_provides_invalid_json_test.dart @@ -14,7 +14,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/package_validation_has_a_warning_and_continues_test.dart b/test/lish/package_validation_has_a_warning_and_continues_test.dart index 61c169a3f..a0c0bc666 100644 --- a/test/lish/package_validation_has_a_warning_and_continues_test.dart +++ b/test/lish/package_validation_has_a_warning_and_continues_test.dart @@ -23,7 +23,7 @@ void main() { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); expect(pub.stdout, emitsThrough(startsWith('Package has 1 warning.'))); pub.stdin.writeln('y'); handleUploadForm(globalServer); diff --git a/test/lish/package_validation_has_a_warning_and_is_canceled_test.dart b/test/lish/package_validation_has_a_warning_and_is_canceled_test.dart index f44b3a40a..ccd221e78 100644 --- a/test/lish/package_validation_has_a_warning_and_is_canceled_test.dart +++ b/test/lish/package_validation_has_a_warning_and_is_canceled_test.dart @@ -11,7 +11,7 @@ import '../test_pub.dart'; void main() { test('package validation has a warning and is canceled', () async { await d.validPackage().create(); - var pkg = packageMap( + final pkg = packageMap( 'test_pkg', '1.0.0', null, @@ -24,7 +24,7 @@ void main() { ]).create(); await servePackages(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); pub.stdin.writeln('n'); await pub.shouldExit(exit_codes.DATA); diff --git a/test/lish/package_validation_has_an_error_test.dart b/test/lish/package_validation_has_an_error_test.dart index 1f47c68ba..46c75d73c 100644 --- a/test/lish/package_validation_has_an_error_test.dart +++ b/test/lish/package_validation_has_an_error_test.dart @@ -20,7 +20,7 @@ void main() { ]).create(); await servePackages(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await pub.shouldExit(exit_codes.DATA); expect( diff --git a/test/lish/server_arg_overrides_publish_to_url_test.dart b/test/lish/server_arg_overrides_publish_to_url_test.dart index dd05b7c87..ea245a728 100644 --- a/test/lish/server_arg_overrides_publish_to_url_test.dart +++ b/test/lish/server_arg_overrides_publish_to_url_test.dart @@ -15,7 +15,7 @@ void main() { // try to ping it, and will use multiple retries when doing so. final packageServer = await startPackageServer(); - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['publish_to'] = 'http://pubspec.com'; await d.dir(appPath, [d.pubspec(pkg)]).create(); await runPub( diff --git a/test/lish/skip_validation_test.dart b/test/lish/skip_validation_test.dart index e9b3dc049..885b58050 100644 --- a/test/lish/skip_validation_test.dart +++ b/test/lish/skip_validation_test.dart @@ -33,7 +33,7 @@ void main() { await d.credentialsFile(globalServer, 'access-token').create(); await servePackages(); - var pub = await startPublish(globalServer, args: ['--skip-validation']); + final pub = await startPublish(globalServer, args: ['--skip-validation']); await confirmPublish(pub); diff --git a/test/lish/unicode_file_names_test.dart b/test/lish/unicode_file_names_test.dart index a07e207e2..ec3be5b8a 100644 --- a/test/lish/unicode_file_names_test.dart +++ b/test/lish/unicode_file_names_test.dart @@ -19,7 +19,7 @@ void main() { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); handleUploadForm(globalServer); diff --git a/test/lish/upload_form_fields_has_a_non_string_value_test.dart b/test/lish/upload_form_fields_has_a_non_string_value_test.dart index e4c8bd583..44eca65c6 100644 --- a/test/lish/upload_form_fields_has_a_non_string_value_test.dart +++ b/test/lish/upload_form_fields_has_a_non_string_value_test.dart @@ -15,11 +15,11 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); - var body = { + final body = { 'url': 'http://example.com/upload', 'fields': {'field': 12}, }; diff --git a/test/lish/upload_form_fields_is_not_a_map_test.dart b/test/lish/upload_form_fields_is_not_a_map_test.dart index 4701d4456..bad76ec16 100644 --- a/test/lish/upload_form_fields_is_not_a_map_test.dart +++ b/test/lish/upload_form_fields_is_not_a_map_test.dart @@ -15,11 +15,11 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); - var body = {'url': 'http://example.com/upload', 'fields': 12}; + final body = {'url': 'http://example.com/upload', 'fields': 12}; handleUploadForm(globalServer, body: body); expect(pub.stderr, emits('Invalid server response:')); expect(pub.stderr, emits(jsonEncode(body))); diff --git a/test/lish/upload_form_is_missing_fields_test.dart b/test/lish/upload_form_is_missing_fields_test.dart index 8aee08acd..2c0beccaa 100644 --- a/test/lish/upload_form_is_missing_fields_test.dart +++ b/test/lish/upload_form_is_missing_fields_test.dart @@ -15,11 +15,11 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); - var body = {'url': 'http://example.com/upload'}; + final body = {'url': 'http://example.com/upload'}; handleUploadForm(globalServer, body: body); expect(pub.stderr, emits('Invalid server response:')); expect(pub.stderr, emits(jsonEncode(body))); diff --git a/test/lish/upload_form_is_missing_url_test.dart b/test/lish/upload_form_is_missing_url_test.dart index 30364b4ae..0b8c8737c 100644 --- a/test/lish/upload_form_is_missing_url_test.dart +++ b/test/lish/upload_form_is_missing_url_test.dart @@ -15,11 +15,11 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); - var body = { + final body = { 'fields': {'field1': 'value1', 'field2': 'value2'}, }; diff --git a/test/lish/upload_form_provides_an_error_test.dart b/test/lish/upload_form_provides_an_error_test.dart index f39e8249e..2e62e923d 100644 --- a/test/lish/upload_form_provides_an_error_test.dart +++ b/test/lish/upload_form_provides_an_error_test.dart @@ -15,7 +15,7 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); diff --git a/test/lish/upload_form_provides_invalid_json_test.dart b/test/lish/upload_form_provides_invalid_json_test.dart index 1b64d5f28..1c12f0cc6 100644 --- a/test/lish/upload_form_provides_invalid_json_test.dart +++ b/test/lish/upload_form_provides_invalid_json_test.dart @@ -14,7 +14,7 @@ void main() { await d.validPackage().create(); await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); diff --git a/test/lish/upload_form_url_is_not_a_string_test.dart b/test/lish/upload_form_url_is_not_a_string_test.dart index 9fb642c95..20f8312cf 100644 --- a/test/lish/upload_form_url_is_not_a_string_test.dart +++ b/test/lish/upload_form_url_is_not_a_string_test.dart @@ -15,11 +15,11 @@ void main() { await servePackages(); await d.validPackage().create(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); - var body = { + final body = { 'url': 12, 'fields': {'field1': 'value1', 'field2': 'value2'}, }; diff --git a/test/lish/uses_publish_to_url_test.dart b/test/lish/uses_publish_to_url_test.dart index 57d7de215..c389b145d 100644 --- a/test/lish/uses_publish_to_url_test.dart +++ b/test/lish/uses_publish_to_url_test.dart @@ -12,7 +12,7 @@ import '../test_pub.dart'; void main() { test('uses the publish_to URL', () async { final server = await servePackages(); - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['publish_to'] = server.url; await d.dir(appPath, [d.pubspec(pkg)]).create(); await runPub( diff --git a/test/lock_file_test.dart b/test/lock_file_test.dart index 282a7c96b..93b236480 100644 --- a/test/lock_file_test.dart +++ b/test/lock_file_test.dart @@ -17,17 +17,17 @@ void main() { group('LockFile', () { group('parse()', () { test('returns an empty lockfile if the contents are empty', () { - var lockFile = LockFile.parse('', sources); + final lockFile = LockFile.parse('', sources); expect(lockFile.packages.length, equals(0)); }); test('returns an empty lockfile if the contents are whitespace', () { - var lockFile = LockFile.parse(' \t\n ', sources); + final lockFile = LockFile.parse(' \t\n ', sources); expect(lockFile.packages.length, equals(0)); }); test('parses a series of package descriptions', () { - var lockFile = LockFile.parse( + final lockFile = LockFile.parse( ''' packages: bar: @@ -48,7 +48,7 @@ packages: expect(lockFile.packages.length, equals(2)); - var bar = lockFile.packages['bar']!; + final bar = lockFile.packages['bar']!; expect(bar.name, equals('bar')); expect(bar.version, equals(Version(1, 2, 3))); expect(bar.source, equals(cache.hosted)); @@ -57,7 +57,7 @@ packages: equals('https://bar.com'), ); - var foo = lockFile.packages['foo']!; + final foo = lockFile.packages['foo']!; expect(foo.name, equals('foo')); expect(foo.version, equals(Version(2, 3, 4))); expect(foo.source, equals(cache.hosted)); @@ -68,7 +68,7 @@ packages: }); test('allows an unknown source', () { - var lockFile = LockFile.parse( + final lockFile = LockFile.parse( ''' packages: foo: @@ -78,12 +78,12 @@ packages: ''', cache.sources, ); - var foo = lockFile.packages['foo']!; + final foo = lockFile.packages['foo']!; expect(foo.source, equals(sources('bad'))); }); test('allows an empty dependency map', () { - var lockFile = LockFile.parse( + final lockFile = LockFile.parse( ''' packages: ''', @@ -93,7 +93,7 @@ packages: }); test('allows an old-style SDK constraint', () { - var lockFile = LockFile.parse('sdk: ">=1.2.3 <4.0.0"', sources); + final lockFile = LockFile.parse('sdk: ">=1.2.3 <4.0.0"', sources); expect( lockFile.sdkConstraints['dart']!.effectiveConstraint, VersionConstraint.parse('>=1.2.3 <4.0.0'), @@ -103,7 +103,7 @@ packages: }); test('allows new-style SDK constraints', () { - var lockFile = LockFile.parse( + final lockFile = LockFile.parse( ''' sdks: dart: ">=1.2.3 <4.0.0" @@ -367,7 +367,7 @@ packages: }); test('serialize() dumps the lockfile to YAML', () { - var lockfile = LockFile( + final lockfile = LockFile( [ PackageId( 'foo', diff --git a/test/oauth2/utils.dart b/test/oauth2/utils.dart index 05636e295..dc9da936c 100644 --- a/test/oauth2/utils.dart +++ b/test/oauth2/utils.dart @@ -24,8 +24,8 @@ Future authorizePub( 'behalf.'), ); - var line = await pub.stdout.next; - var match = + final line = await pub.stdout.next; + final match = RegExp(r'[?&]redirect_uri=([0-9a-zA-Z.%+-]+)[$&]').firstMatch(line)!; expect(match, isNotNull); @@ -37,14 +37,14 @@ Future authorizePub( // Call the redirect url as the browser would otherwise do after successful // sign-in with Google account. - var response = + final response = await (http.Request('GET', redirectUrl)..followRedirects = false).send(); expect(response.headers['location'], equals('https://pub.dev/authorized')); } void handleAccessTokenRequest(PackageServer server, String accessToken) { server.expect('POST', '/token', (request) async { - var body = await request.readAsString(); + final body = await request.readAsString(); expect(body, matches(RegExp(r'(^|&)code=access\+code(&|$)'))); return shelf.Response.ok( @@ -57,14 +57,14 @@ void handleAccessTokenRequest(PackageServer server, String accessToken) { /// Adds additional query parameters to [url], overwriting the original /// parameters if a name conflict occurs. Uri _addQueryParameters(Uri url, Map parameters) { - var queryMap = queryToMap(url.query); + final queryMap = queryToMap(url.query); queryMap.addAll(parameters); return url.resolve('?${_mapToQuery(queryMap)}'); } /// Convert a [Map] from parameter names to values to a URL query string. String _mapToQuery(Map map) { - var pairs = >[]; + final pairs = >[]; map.forEach((key, value) { key = Uri.encodeQueryComponent(key); value = (value == null || value.isEmpty) diff --git a/test/oauth2/with_a_malformed_credentials_authenticates_again_test.dart b/test/oauth2/with_a_malformed_credentials_authenticates_again_test.dart index e2192def0..d4e62ac6f 100644 --- a/test/oauth2/with_a_malformed_credentials_authenticates_again_test.dart +++ b/test/oauth2/with_a_malformed_credentials_authenticates_again_test.dart @@ -18,7 +18,7 @@ void main() { await servePackages(); await configDir([d.file('pub-credentials.json', '{bad json')]).create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); await authorizePub(pub, globalServer, 'new access token'); diff --git a/test/oauth2/with_a_pre_existing_credentials_does_not_authenticate_test.dart b/test/oauth2/with_a_pre_existing_credentials_does_not_authenticate_test.dart index 860de444b..316955883 100644 --- a/test/oauth2/with_a_pre_existing_credentials_does_not_authenticate_test.dart +++ b/test/oauth2/with_a_pre_existing_credentials_does_not_authenticate_test.dart @@ -13,7 +13,7 @@ void main() { await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); diff --git a/test/oauth2/with_a_server_rejected_refresh_token_authenticates_again_test.dart b/test/oauth2/with_a_server_rejected_refresh_token_authenticates_again_test.dart index 0669cb6db..45d3e8b9c 100644 --- a/test/oauth2/with_a_server_rejected_refresh_token_authenticates_again_test.dart +++ b/test/oauth2/with_a_server_rejected_refresh_token_authenticates_again_test.dart @@ -29,7 +29,7 @@ void main() { ) .create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); globalServer.expect('POST', '/token', (request) { return request.read().drain().then((_) { @@ -46,7 +46,7 @@ void main() { await expectLater(pub.stdout, emits(startsWith('Uploading...'))); await authorizePub(pub, globalServer, 'new access token'); - var done = Completer(); + final done = Completer(); globalServer.expect('GET', '/api/packages/versions/new', (request) async { expect( request.headers, diff --git a/test/oauth2/with_an_expired_credentials_refreshes_and_saves_test.dart b/test/oauth2/with_an_expired_credentials_refreshes_and_saves_test.dart index 4f9050c68..7686b846e 100644 --- a/test/oauth2/with_an_expired_credentials_refreshes_and_saves_test.dart +++ b/test/oauth2/with_an_expired_credentials_refreshes_and_saves_test.dart @@ -26,7 +26,7 @@ void main() { ) .create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); globalServer.expect('POST', '/token', (request) { diff --git a/test/oauth2/with_an_expired_credentials_without_a_refresh_token_authenticates_again_test.dart b/test/oauth2/with_an_expired_credentials_without_a_refresh_token_authenticates_again_test.dart index a5e495ab4..9814e8c9d 100644 --- a/test/oauth2/with_an_expired_credentials_without_a_refresh_token_authenticates_again_test.dart +++ b/test/oauth2/with_an_expired_credentials_without_a_refresh_token_authenticates_again_test.dart @@ -24,7 +24,7 @@ void main() { ) .create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); await expectLater( diff --git a/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart b/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart index 6ea28834d..9562345e9 100644 --- a/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart +++ b/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart @@ -15,7 +15,7 @@ void main() { 'credentials.json', () async { await d.validPackage().create(); await servePackages(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); await authorizePub(pub, globalServer); diff --git a/test/oauth2/with_server_rejected_credentials_authenticates_again_test.dart b/test/oauth2/with_server_rejected_credentials_authenticates_again_test.dart index 4b85a0461..8deb238e6 100644 --- a/test/oauth2/with_server_rejected_credentials_authenticates_again_test.dart +++ b/test/oauth2/with_server_rejected_credentials_authenticates_again_test.dart @@ -17,7 +17,7 @@ void main() { await d.validPackage().create(); await servePackages(); await d.credentialsFile(globalServer, 'access-token').create(); - var pub = await startPublish(globalServer); + final pub = await startPublish(globalServer); await confirmPublish(pub); diff --git a/test/package_config_file_test.dart b/test/package_config_file_test.dart index d5d052b0c..9353a2fce 100644 --- a/test/package_config_file_test.dart +++ b/test/package_config_file_test.dart @@ -81,7 +81,7 @@ void main() { d.dir('lib'), ]).create(); - var oldFile = d.dir(appPath, [ + final oldFile = d.dir(appPath, [ d.packageConfigFile([ d.packageConfigEntry( name: 'notFoo', diff --git a/test/package_server.dart b/test/package_server.dart index 1b142b2b8..d39168f57 100644 --- a/test/package_server.dart +++ b/test/package_server.dart @@ -300,7 +300,7 @@ class PackageServer { String? sdk, Map>? headers, }) { - var pubspecFields = { + final pubspecFields = { 'name': name, 'version': version, 'environment': {'sdk': sdk ?? '^3.0.0'}, @@ -311,7 +311,7 @@ class PackageServer { contents ??= [d.libDir(name, '$name $version')]; contents = [d.file('pubspec.yaml', yaml(pubspecFields)), ...contents]; - var package = _packages.putIfAbsent(name, _ServedPackage.new); + final package = _packages.putIfAbsent(name, _ServedPackage.new); package.versions[version] = _ServedPackageVersion( pubspecFields, headers: headers, diff --git a/test/pubspec_test.dart b/test/pubspec_test.dart index cbbb0cf20..899c1dbc4 100644 --- a/test/pubspec_test.dart +++ b/test/pubspec_test.dart @@ -17,7 +17,7 @@ void main() { group('parse()', () { final sources = SystemCache().sources; - var throwsPubspecException = + final throwsPubspecException = throwsA(const TypeMatcher()); void expectPubspecException( @@ -35,7 +35,7 @@ void main() { ); } - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( contents, sources, containingDescription: containingDescription ?? RootDescription('.'), @@ -81,7 +81,7 @@ void main() { }); test('allows a version constraint for dependencies', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependencies: foo: @@ -94,7 +94,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.constraint.allows(Version(1, 2, 3)), isTrue); expect(foo.constraint.allows(Version(1, 2, 5)), isTrue); @@ -102,7 +102,7 @@ dependencies: }); test('allows empty version constraint', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependencies: foo: @@ -115,13 +115,13 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.constraint.isEmpty, isTrue); }); test('allows an empty dependencies map', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependencies: ''', @@ -133,7 +133,7 @@ dependencies: }); test('allows a version constraint for dev dependencies', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dev_dependencies: foo: @@ -146,7 +146,7 @@ dev_dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.devDependencies['foo']!; + final foo = pubspec.devDependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.constraint.allows(Version(1, 2, 3)), isTrue); expect(foo.constraint.allows(Version(1, 2, 5)), isTrue); @@ -154,7 +154,7 @@ dev_dependencies: }); test('allows an empty dev dependencies map', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dev_dependencies: ''', @@ -166,7 +166,7 @@ dev_dependencies: }); test('allows a version constraint for dependency overrides', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependency_overrides: foo: @@ -179,7 +179,7 @@ dependency_overrides: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencyOverrides['foo']!; + final foo = pubspec.dependencyOverrides['foo']!; expect(foo.name, equals('foo')); expect(foo.constraint.allows(Version(1, 2, 3)), isTrue); expect(foo.constraint.allows(Version(1, 2, 5)), isTrue); @@ -187,7 +187,7 @@ dependency_overrides: }); test('allows an empty dependency overrides map', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependency_overrides: ''', @@ -199,7 +199,7 @@ dependency_overrides: }); test('allows an unknown source', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependencies: foo: @@ -209,13 +209,13 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source, equals(sources('unknown'))); }); test('allows a default source', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' dependencies: foo: @@ -225,7 +225,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source, equals(sources('hosted'))); }); @@ -445,7 +445,7 @@ resolution: "sometimes"''', }); test('allows comment-only files', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' # No external dependencies yet # Including for completeness @@ -477,7 +477,7 @@ dependencies: group('source dependencies', () { test('with url and name', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg dependencies: @@ -490,7 +490,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source.name, 'hosted'); expect( @@ -505,7 +505,7 @@ dependencies: }); test('with url only', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg environment: @@ -519,7 +519,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source.name, 'hosted'); expect( @@ -534,7 +534,7 @@ dependencies: }); test('with url as string', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg environment: @@ -547,7 +547,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source.name, 'hosted'); expect( @@ -562,7 +562,7 @@ dependencies: }); test('interprets string description as name for older versions', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg environment: @@ -575,7 +575,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source.name, 'hosted'); expect( @@ -592,7 +592,7 @@ dependencies: test( 'reports helpful span when using new syntax with invalid environment', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg environment: @@ -616,7 +616,7 @@ dependencies: ); test('without a description', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: pkg dependencies: @@ -626,7 +626,7 @@ dependencies: containingDescription: RootDescription('.'), ); - var foo = pubspec.dependencies['foo']!; + final foo = pubspec.dependencies['foo']!; expect(foo.name, equals('foo')); expect(foo.source.name, 'hosted'); expect( @@ -730,7 +730,7 @@ dependencies: group('environment', () { test('allows an omitted environment', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( 'name: testing', sources, containingDescription: RootDescription('.'), @@ -745,7 +745,7 @@ dependencies: }); test('default SDK constraint can be omitted with empty environment', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( '', sources, containingDescription: RootDescription('.'), @@ -759,7 +759,7 @@ dependencies: }); test('defaults the upper constraint for the SDK', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' name: test environment: @@ -779,7 +779,7 @@ dependencies: test( 'default upper constraint for the SDK applies only if compatible ' 'with the lower bound', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' environment: sdk: ">3.0.0" @@ -806,7 +806,7 @@ dependencies: }); test('allows a version constraint for the SDKs', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' environment: sdk: ">=1.2.3 <2.3.4" @@ -875,7 +875,7 @@ environment: group('publishTo', () { test('defaults to null if omitted', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( '', sources, containingDescription: RootDescription('.'), @@ -891,7 +891,7 @@ environment: }); test('allows a URL', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' publish_to: http://example.com ''', @@ -902,7 +902,7 @@ publish_to: http://example.com }); test('allows none', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' publish_to: none ''', @@ -929,7 +929,7 @@ publish_to: none group('executables', () { test('defaults to an empty map if omitted', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( '', sources, containingDescription: RootDescription('.'), @@ -938,7 +938,7 @@ publish_to: none }); test('allows simple names for keys and most characters in values', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' executables: abcDEF-123_: "abc DEF-123._" @@ -992,7 +992,7 @@ executables: }); test('uses the key if the value is null', () { - var pubspec = Pubspec.parse( + final pubspec = Pubspec.parse( ''' executables: command: @@ -1035,12 +1035,12 @@ dependency_overrides: ); } - var pubspec = parsePubspecOverrides(contents); + final pubspec = parsePubspecOverrides(contents); expect(() => fn(pubspec), throwsA(expectation)); } test('allows empty overrides file', () { - var pubspec = parsePubspecOverrides(''); + final pubspec = parsePubspecOverrides(''); expect(pubspec.dependencyOverrides['foo'], isNull); final bar = pubspec.dependencyOverrides['bar']!; expect(bar.name, equals('bar')); diff --git a/test/remove/remove_test.dart b/test/remove/remove_test.dart index c2787f0fc..7c5fbc6fd 100644 --- a/test/remove/remove_test.dart +++ b/test/remove/remove_test.dart @@ -213,7 +213,7 @@ environment: final server = await servePackages(); server.serve('bar', '2.0.1'); - var custom = await startPackageServer(); + final custom = await startPackageServer(); custom.serve('foo', '1.2.3'); await d.appDir( diff --git a/test/run/allows_dart_extension_test.dart b/test/run/allows_dart_extension_test.dart index 62475bc9d..36557adee 100644 --- a/test/run/allows_dart_extension_test.dart +++ b/test/run/allows_dart_extension_test.dart @@ -25,7 +25,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['script.dart']); + final pub = await pubRun(args: ['script.dart']); expect(pub.stdout, emitsThrough('stdout output')); expect(pub.stderr, emitsThrough('stderr output')); await pub.shouldExit(123); diff --git a/test/run/app_can_read_from_stdin_test.dart b/test/run/app_can_read_from_stdin_test.dart index 646e7e50b..0084be445 100644 --- a/test/run/app_can_read_from_stdin_test.dart +++ b/test/run/app_can_read_from_stdin_test.dart @@ -28,7 +28,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['bin/script']); + final pub = await pubRun(args: ['bin/script']); await expectLater(pub.stdout, emitsThrough('started')); pub.stdin.writeln('first'); @@ -55,7 +55,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['bin/script']); + final pub = await pubRun(args: ['bin/script']); await expectLater(pub.stdout, emitsThrough('started')); pub.stdin.writeln('first'); diff --git a/test/run/errors_if_only_transitive_dependency_test.dart b/test/run/errors_if_only_transitive_dependency_test.dart index 1ba780e94..472399082 100644 --- a/test/run/errors_if_only_transitive_dependency_test.dart +++ b/test/run/errors_if_only_transitive_dependency_test.dart @@ -35,7 +35,7 @@ void main() { await pubGet(); - var pub = await pubRun(args: ['foo:script']); + final pub = await pubRun(args: ['foo:script']); expect(pub.stderr, emits('Package "foo" is not an immediate dependency.')); expect( pub.stderr, diff --git a/test/run/forwards_signal_posix_test.dart b/test/run/forwards_signal_posix_test.dart index cfb18da45..ec0b3e3ff 100644 --- a/test/run/forwards_signal_posix_test.dart +++ b/test/run/forwards_signal_posix_test.dart @@ -47,7 +47,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['bin/script']); + final pub = await pubRun(args: ['bin/script']); await expectLater(pub.stdout, emitsThrough('ready')); for (var signal in _catchableSignals) { diff --git a/test/run/includes_parent_directories_of_entrypoint_test.dart b/test/run/includes_parent_directories_of_entrypoint_test.dart index 7156039da..668714d52 100644 --- a/test/run/includes_parent_directories_of_entrypoint_test.dart +++ b/test/run/includes_parent_directories_of_entrypoint_test.dart @@ -32,7 +32,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: [p.join('tool', 'a', 'b', 'app')]); + final pub = await pubRun(args: [p.join('tool', 'a', 'b', 'app')]); expect(pub.stdout, emitsThrough('a b')); await pub.shouldExit(); }); diff --git a/test/run/loads_package_imports_in_a_dependency_test.dart b/test/run/loads_package_imports_in_a_dependency_test.dart index 192cdbf84..87e550628 100644 --- a/test/run/loads_package_imports_in_a_dependency_test.dart +++ b/test/run/loads_package_imports_in_a_dependency_test.dart @@ -30,7 +30,7 @@ main() => print(value); ]).create(); await pubGet(); - var pub = await pubRun(args: ['foo:bar']); + final pub = await pubRun(args: ['foo:bar']); expect(pub.stdout, emitsThrough('foobar')); await pub.shouldExit(); }); diff --git a/test/run/nonexistent_dependency_test.dart b/test/run/nonexistent_dependency_test.dart index 955cdaa14..1f420fabd 100644 --- a/test/run/nonexistent_dependency_test.dart +++ b/test/run/nonexistent_dependency_test.dart @@ -13,7 +13,7 @@ void main() { await d.dir(appPath, [d.appPubspec()]).create(); await pubGet(); - var pub = await pubRun(args: ['foo:script']); + final pub = await pubRun(args: ['foo:script']); expect( pub.stderr, emits('Could not find package "foo". Did you forget to add a ' diff --git a/test/run/nonexistent_script_in_dependency_test.dart b/test/run/nonexistent_script_in_dependency_test.dart index 3179e0c51..15c0e3e43 100644 --- a/test/run/nonexistent_script_in_dependency_test.dart +++ b/test/run/nonexistent_script_in_dependency_test.dart @@ -23,7 +23,7 @@ void main() { await pubGet(); - var pub = await pubRun(args: ['foo:script']); + final pub = await pubRun(args: ['foo:script']); expect( pub.stderr, emits( diff --git a/test/run/nonexistent_script_test.dart b/test/run/nonexistent_script_test.dart index 4ebb8c038..37b26ae5e 100644 --- a/test/run/nonexistent_script_test.dart +++ b/test/run/nonexistent_script_test.dart @@ -14,7 +14,7 @@ void main() { await d.dir(appPath, [d.appPubspec()]).create(); await pubGet(); - var pub = await pubRun(args: [p.join('bin', 'script')]); + final pub = await pubRun(args: [p.join('bin', 'script')]); expect( pub.stderr, emits("Could not find ${p.join("bin", "script.dart")}."), diff --git a/test/run/package_api_test.dart b/test/run/package_api_test.dart index 4be659c07..6d95d9d40 100644 --- a/test/run/package_api_test.dart +++ b/test/run/package_api_test.dart @@ -34,7 +34,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['bin/script']); + final pub = await pubRun(args: ['bin/script']); expect( pub.stdout, @@ -71,7 +71,7 @@ void main() { await pubGet(); - var pub = await pubRun(args: ['foo:script']); + final pub = await pubRun(args: ['foo:script']); expect(pub.stdout, emitsThrough('Building package executable...')); expect(pub.stdout, emits('Built foo:script.')); @@ -87,7 +87,7 @@ void main() { pub.stdout, emits(p.toUri(p.join(d.sandbox, 'myapp/lib/resource.txt')).toString()), ); - var fooResourcePath = + final fooResourcePath = p.join(globalServer.pathInCache('foo', '1.0.0'), 'lib/resource.txt'); expect(pub.stdout, emits(p.toUri(fooResourcePath).toString())); await pub.shouldExit(0); diff --git a/test/run/passes_along_arguments_test.dart b/test/run/passes_along_arguments_test.dart index 4f372c217..15f383c27 100644 --- a/test/run/passes_along_arguments_test.dart +++ b/test/run/passes_along_arguments_test.dart @@ -24,7 +24,8 @@ void main() { // Use some args that would trip up pub's arg parser to ensure that it // isn't trying to look at them. - var pub = await pubRun(args: ['bin/args', '--verbose', '-m', '--', 'help']); + final pub = + await pubRun(args: ['bin/args', '--verbose', '-m', '--', 'help']); expect(pub.stdout, emitsThrough('--verbose -m -- help')); await pub.shouldExit(); diff --git a/test/run/precompile_test.dart b/test/run/precompile_test.dart index 263eddeea..856f0bd57 100644 --- a/test/run/precompile_test.dart +++ b/test/run/precompile_test.dart @@ -38,7 +38,7 @@ void main() { test('`pub run` precompiles script', () async { await setupForPubRunToPrecompile(); - var pub = await pubRun(args: ['test']); + final pub = await pubRun(args: ['test']); await pub.shouldExit(0); final lines = await pub.stdout.rest.toList(); expect(lines, contains('Building package executable...')); @@ -50,7 +50,7 @@ void main() { () async { await setupForPubRunToPrecompile(); - var pub = await pubRun(args: ['test'], verbose: false); + final pub = await pubRun(args: ['test'], verbose: false); await pub.shouldExit(0); final lines = await pub.stdout.rest.toList(); expect(lines, isNot(contains('Building package executable...'))); @@ -77,7 +77,7 @@ void main() { environment: {'PUB_CACHE': '.pub_cache'}, ); - var pub = await pubRun( + final pub = await pubRun( args: ['test'], environment: {'PUB_CACHE': '.pub_cache'}, ); @@ -106,7 +106,7 @@ void main() { output: contains('Building package executables...'), ); - var pub = await pubRun( + final pub = await pubRun( args: ['test'], ); await pub.shouldExit(0); @@ -136,7 +136,7 @@ void main() { output: contains('Building package executables...'), ); - var pub = await pubRun( + final pub = await pubRun( args: ['test'], environment: {'PUB_CACHE': '.pub_cache'}, ); diff --git a/test/run/runs_app_in_entrypoint_test.dart b/test/run/runs_app_in_entrypoint_test.dart index 6e471684c..d2aba0f71 100644 --- a/test/run/runs_app_in_entrypoint_test.dart +++ b/test/run/runs_app_in_entrypoint_test.dart @@ -25,7 +25,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['bin/script']); + final pub = await pubRun(args: ['bin/script']); expect(pub.stdout, emitsThrough('stdout output')); expect(pub.stderr, emits('stderr output')); await pub.shouldExit(123); diff --git a/test/run/runs_named_app_in_dependency_test.dart b/test/run/runs_named_app_in_dependency_test.dart index 25774cffe..0f0cc61c0 100644 --- a/test/run/runs_named_app_in_dependency_test.dart +++ b/test/run/runs_named_app_in_dependency_test.dart @@ -23,7 +23,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['foo:bar']); + final pub = await pubRun(args: ['foo:bar']); expect(pub.stdout, emitsThrough('foobar')); await pub.shouldExit(); }); diff --git a/test/run/runs_named_app_in_dev_dependency_test.dart b/test/run/runs_named_app_in_dev_dependency_test.dart index b38239992..158ddbed8 100644 --- a/test/run/runs_named_app_in_dev_dependency_test.dart +++ b/test/run/runs_named_app_in_dev_dependency_test.dart @@ -24,7 +24,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['foo:bar']); + final pub = await pubRun(args: ['foo:bar']); expect(pub.stdout, emitsThrough('foobar')); await pub.shouldExit(); }); diff --git a/test/run/runs_shorthand_app_in_dependency_test.dart b/test/run/runs_shorthand_app_in_dependency_test.dart index 86002dc10..e4d1aa351 100644 --- a/test/run/runs_shorthand_app_in_dependency_test.dart +++ b/test/run/runs_shorthand_app_in_dependency_test.dart @@ -24,7 +24,7 @@ void main() { ]).create(); await pubGet(); - var pub = await pubRun(args: ['foo']); + final pub = await pubRun(args: ['foo']); expect(pub.stdout, emitsThrough('foo')); await pub.shouldExit(); }); diff --git a/test/snapshot_test.dart b/test/snapshot_test.dart index 1d515ef82..c2dea39b5 100644 --- a/test/snapshot_test.dart +++ b/test/snapshot_test.dart @@ -146,7 +146,7 @@ void main() { d.file('hello.dart-$versionSuffix.snapshot', contains('hello 2!')), ]).validate(); - var process = await pubRun(args: ['foo:hello']); + final process = await pubRun(args: ['foo:hello']); expect(process.stdout, emits('hello 2!')); await process.shouldExit(); }); @@ -206,7 +206,7 @@ void main() { d.file('hello.dart-$versionSuffix.snapshot', contains('hello 2!')), ]).validate(); - var process = await pubRun(args: ['foo:hello']); + final process = await pubRun(args: ['foo:hello']); expect(process.stdout, emits('hello 2!')); await process.shouldExit(); }); @@ -253,7 +253,7 @@ void main() { d.file('hello.dart-$versionSuffix.snapshot', contains('Goodbye!')), ]).validate(); - var process = await pubRun(args: ['foo:hello']); + final process = await pubRun(args: ['foo:hello']); expect(process.stdout, emits('Goodbye!')); await process.shouldExit(); }); @@ -282,7 +282,7 @@ void main() { ), ]).create(); - var process = await pubRun(args: ['foo:hello']); + final process = await pubRun(args: ['foo:hello']); // In the real world this would just print "hello!", but since we collect // all output we see the precompilation messages as well. diff --git a/test/test_pub.dart b/test/test_pub.dart index 380c66685..ad80b4255 100644 --- a/test/test_pub.dart +++ b/test/test_pub.dart @@ -159,7 +159,7 @@ Future pubCommand( throw ArgumentError("Cannot pass both 'error' and 'warning'."); } - var allArgs = [command.name]; + final allArgs = [command.name]; if (args != null) allArgs.addAll(args); output ??= command.success; @@ -301,9 +301,9 @@ Future pubRun({ Map? environment, bool verbose = true, }) async { - var pubArgs = global ? ['global', 'run'] : ['run']; + final pubArgs = global ? ['global', 'run'] : ['run']; pubArgs.addAll(args); - var pub = await startPub( + final pub = await startPub( args: pubArgs, environment: environment, verbose: verbose, @@ -358,7 +358,7 @@ Future runPub({ // Cannot pass both output and outputJson. assert(output == null || outputJson == null); - var pub = await startPub( + final pub = await startPub( args: args, workingDirectory: workingDirectory, environment: environment, @@ -372,11 +372,11 @@ Future runPub({ await pub.shouldExit(exitCode); - var actualOutput = (await pub.stdoutStream().toList()).join('\n'); - var actualError = (await pub.stderrStream().toList()).join('\n'); - var actualSilent = (await pub.silentStream().toList()).join('\n'); + final actualOutput = (await pub.stdoutStream().toList()).join('\n'); + final actualError = (await pub.stderrStream().toList()).join('\n'); + final actualSilent = (await pub.silentStream().toList()).join('\n'); - var failures = []; + final failures = []; if (outputJson == null) { _validateOutput(failures, 'stdout', output, actualOutput); } else { @@ -404,7 +404,7 @@ Future startPublish( String path = '', String? workingDirectory, }) async { - var tokenEndpoint = Uri.parse(server.url).resolve('/token').toString(); + final tokenEndpoint = Uri.parse(server.url).resolve('/token').toString(); args = ['lish', ...?args]; return await startPub( args: args, @@ -510,7 +510,7 @@ Future startPub({ final dotPackagesPath = (await Isolate.packageConfig).toString(); - var dartArgs = ['--packages=$dotPackagesPath', '--enable-asserts']; + final dartArgs = ['--packages=$dotPackagesPath', '--enable-asserts']; dartArgs ..addAll([pubPath, if (!verbose) '--verbosity=normal']) ..addAll(args); @@ -531,7 +531,7 @@ Future startPub({ ...getPubTestEnvironment(tokenEndpoint), }; for (final e in (environment ?? {}).entries) { - var value = e.value; + final value = e.value; if (value == null) { mergedEnvironment.remove(e.key); } else { @@ -576,7 +576,7 @@ class PubProcess extends TestProcess { Encoding encoding = utf8, bool forwardStdio = false, }) async { - var process = await Process.start( + final process = await Process.start( executable, arguments.toList(), workingDirectory: workingDirectory, @@ -586,7 +586,7 @@ class PubProcess extends TestProcess { ); if (description == null) { - var humanExecutable = p.isWithin(p.current, executable) + final humanExecutable = p.isWithin(p.current, executable) ? p.relative(executable) : executable; description = '$humanExecutable ${arguments.join(' ')}'; @@ -627,10 +627,10 @@ class PubProcess extends TestProcess { ) { late log.Level lastLevel; return stream.map((line) { - var match = _logLineRegExp.firstMatch(line); + final match = _logLineRegExp.firstMatch(line); if (match == null) return (defaultLevel, line); - var level = _logLevels[match[1]] ?? lastLevel; + final level = _logLevels[match[1]] ?? lastLevel; lastLevel = level; return (level, match[2]!); }); @@ -689,9 +689,9 @@ Future createLockFile( Iterable? dependenciesInSandBox, Map? hosted, }) async { - var cache = SystemCache(rootDir: _pathInSandbox(cachePath)); + final cache = SystemCache(rootDir: _pathInSandbox(cachePath)); - var lockFile = + final lockFile = _createLockFile(cache, sandbox: dependenciesInSandBox, hosted: hosted); await d.dir(package, [ @@ -714,7 +714,7 @@ LockFile _createLockFile( Iterable? sandbox, Map? hosted, }) { - var dependencies = {}; + final dependencies = {}; if (sandbox != null) { for (var package in sandbox) { @@ -755,7 +755,7 @@ LockFile _createLockFile( /// Note that this will only affect HTTP requests made via http.dart in the /// parent process. void useMockClient(MockClient client) { - var oldInnerClient = innerHttpClient; + final oldInnerClient = innerHttpClient; innerHttpClient = client; addTearDown(() { innerHttpClient = oldInnerClient; @@ -771,7 +771,7 @@ Map packageMap( Map? devDependencies, Map? environment, ]) { - var package = { + final package = { 'name': name, 'version': version, 'homepage': 'https://pub.dev', @@ -817,8 +817,8 @@ void _validateOutputString( String expected, String actual, ) { - var actualLines = actual.split('\n'); - var expectedLines = expected.split('\n'); + final actualLines = actual.split('\n'); + final expectedLines = expected.split('\n'); // Strip off the last line. This lets us have expected multiline strings // where the closing ''' is on its own line. It also fixes '' expected output @@ -827,11 +827,11 @@ void _validateOutputString( expectedLines.removeLast(); } - var results = []; + final results = []; var failed = false; // Compare them line by line to see which ones match. - var length = max(expectedLines.length, actualLines.length); + final length = max(expectedLines.length, actualLines.length); for (var i = 0; i < length; i++) { if (i >= actualLines.length) { // Missing output. @@ -842,8 +842,8 @@ void _validateOutputString( failed = true; results.add('X ${actualLines[i]}'); } else { - var expectedLine = expectedLines[i].trim(); - var actualLine = actualLines[i].trim(); + final expectedLine = expectedLines[i].trim(); + final actualLine = actualLines[i].trim(); if (expectedLine != actualLine) { // Mismatched lines. @@ -902,9 +902,9 @@ typedef ValidatorCreator = Validator Function(); /// /// Returns a scheduled Future that contains the validator after validation. Future validatePackage(ValidatorCreator fn, int? size) async { - var cache = SystemCache(rootDir: _pathInSandbox(cachePath)); + final cache = SystemCache(rootDir: _pathInSandbox(cachePath)); final entrypoint = Entrypoint(_pathInSandbox(appPath), cache); - var validator = fn(); + final validator = fn(); validator.context = ValidationContext( entrypoint, await Future.value(size ?? 100), @@ -920,7 +920,7 @@ Future validatePackage(ValidatorCreator fn, int? size) async { /// 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) { - var buffer = StringBuffer(pattern); + final buffer = StringBuffer(pattern); for (var i = 1; i < times; i++) { buffer.write(r'(.|\n)*'); buffer.write(pattern); @@ -942,7 +942,7 @@ String filterUnstableText(String input) { RegExp(r'sha256: "?[0-9a-f]{64}"?', multiLine: true), r'sha256: $SHA256', ); - var port = _globalServer?.port; + final port = _globalServer?.port; if (port != null) { input = input.replaceAll(port.toString(), '\$PORT'); } diff --git a/test/token/error_message_test.dart b/test/token/error_message_test.dart index 26daa4d81..3a9835759 100644 --- a/test/token/error_message_test.dart +++ b/test/token/error_message_test.dart @@ -52,7 +52,7 @@ void main() { }); test('trims and prints long www-authenticate message', () async { - var message = List.generate(2048, (_) => 'a').join(); + final message = List.generate(2048, (_) => 'a').join(); respondWithWwwAuthenticate('bearer realm="pub", message="$message"'); await expectPubErrorMessage( diff --git a/test/token/token_authentication_test.dart b/test/token/token_authentication_test.dart index dd176b62b..64316c2d4 100644 --- a/test/token/token_authentication_test.dart +++ b/test/token/token_authentication_test.dart @@ -19,7 +19,7 @@ void main() { {'url': globalServer.url, 'env': 'TOKEN'}, ], }).create(); - var pub = await startPublish( + final pub = await startPublish( globalServer, overrideDefaultHostedServer: false, environment: {'TOKEN': 'access-token'}, @@ -87,7 +87,7 @@ void main() { {'url': globalServer.url, 'token': 'access-token'}, ], }).create(); - var pub = await startPublish( + final pub = await startPublish( globalServer, overrideDefaultHostedServer: false, ); diff --git a/test/token/when_receives_401_removes_token_test.dart b/test/token/when_receives_401_removes_token_test.dart index ad90b3386..90ec98699 100644 --- a/test/token/when_receives_401_removes_token_test.dart +++ b/test/token/when_receives_401_removes_token_test.dart @@ -18,7 +18,7 @@ void main() { {'url': server.url, 'token': 'access-token'}, ], }).create(); - var pub = await startPublish(server, overrideDefaultHostedServer: false); + final pub = await startPublish(server, overrideDefaultHostedServer: false); await confirmPublish(pub); server.expect('GET', '/api/packages/versions/new', (request) { diff --git a/test/token/when_receives_403_persists_saved_token_test.dart b/test/token/when_receives_403_persists_saved_token_test.dart index 6030855fe..fc800d4b0 100644 --- a/test/token/when_receives_403_persists_saved_token_test.dart +++ b/test/token/when_receives_403_persists_saved_token_test.dart @@ -18,7 +18,7 @@ void main() { {'url': server.url, 'token': 'access-token'}, ], }).create(); - var pub = await startPublish(server, overrideDefaultHostedServer: false); + final pub = await startPublish(server, overrideDefaultHostedServer: false); await confirmPublish(pub); server.expect('GET', '/api/packages/versions/new', (request) { diff --git a/test/transcript_test.dart b/test/transcript_test.dart index 6c225d87c..556b4ae36 100644 --- a/test/transcript_test.dart +++ b/test/transcript_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; void main() { test('discards from the middle once it reaches the maximum', () { - var transcript = Transcript(4); + final transcript = Transcript(4); String forEachToString() { var result = ''; transcript.forEach((entry) => result += entry, (n) => result += '[$n]'); @@ -30,7 +30,7 @@ void main() { }); test("does not discard if it doesn't reach the maximum", () { - var transcript = Transcript(40); + final transcript = Transcript(40); String forEachToString() { var result = ''; transcript.forEach((entry) => result += entry, (n) => result += '[$n]'); diff --git a/test/upgrade/git/do_not_upgrade_if_unneeded_test.dart b/test/upgrade/git/do_not_upgrade_if_unneeded_test.dart index ad5f20f32..37df96f93 100644 --- a/test/upgrade/git/do_not_upgrade_if_unneeded_test.dart +++ b/test/upgrade/git/do_not_upgrade_if_unneeded_test.dart @@ -53,7 +53,7 @@ void main() { ]), ]).validate(); - var originalFooDepSpec = packageSpec('foo_dep'); + final originalFooDepSpec = packageSpec('foo_dep'); await d.git('foo.git', [ d.libDir('foo', 'foo 2'), diff --git a/test/upgrade/git/upgrade_locked_test.dart b/test/upgrade/git/upgrade_locked_test.dart index a12a5a62b..f528a2eba 100644 --- a/test/upgrade/git/upgrade_locked_test.dart +++ b/test/upgrade/git/upgrade_locked_test.dart @@ -41,8 +41,8 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); - var originalBarSpec = packageSpec('bar'); + final originalFooSpec = packageSpec('foo'); + final originalBarSpec = packageSpec('bar'); await d.git( 'foo.git', diff --git a/test/upgrade/git/upgrade_one_locked_test.dart b/test/upgrade/git/upgrade_one_locked_test.dart index eef7db264..089328cd1 100644 --- a/test/upgrade/git/upgrade_one_locked_test.dart +++ b/test/upgrade/git/upgrade_one_locked_test.dart @@ -41,7 +41,7 @@ void main() { ]), ]).validate(); - var originalBarSpec = packageSpec('bar'); + final originalBarSpec = packageSpec('bar'); await d.git( 'foo.git', diff --git a/test/upgrade/git/upgrade_to_incompatible_pubspec_test.dart b/test/upgrade/git/upgrade_to_incompatible_pubspec_test.dart index b45a56fe9..10a660588 100644 --- a/test/upgrade/git/upgrade_to_incompatible_pubspec_test.dart +++ b/test/upgrade/git/upgrade_to_incompatible_pubspec_test.dart @@ -34,7 +34,7 @@ void main() { ]), ]).validate(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await d.git( 'foo.git', diff --git a/test/upgrade/git/upgrade_to_nonexistent_pubspec_test.dart b/test/upgrade/git/upgrade_to_nonexistent_pubspec_test.dart index 9d95e0b34..82f7ebf8c 100644 --- a/test/upgrade/git/upgrade_to_nonexistent_pubspec_test.dart +++ b/test/upgrade/git/upgrade_to_nonexistent_pubspec_test.dart @@ -11,7 +11,7 @@ void main() { test('upgrades Git packages to a nonexistent pubspec', () async { ensureGit(); - var repo = + final repo = d.git('foo.git', [d.libDir('foo'), d.libPubspec('foo', '1.0.0')]); await repo.create(); @@ -23,7 +23,7 @@ void main() { await pubGet(); - var originalFooSpec = packageSpec('foo'); + final originalFooSpec = packageSpec('foo'); await repo.runGit(['rm', 'pubspec.yaml']); await repo.runGit(['commit', '-m', 'delete']); diff --git a/test/utils_test.dart b/test/utils_test.dart index 1ce8869af..3d9c523a4 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -75,7 +75,7 @@ no: 1 }); test('handles non-string map keys', () { - var map = {}; + final map = {}; map[null] = 'null'; map[123] = 'num'; map[true] = 'bool'; @@ -118,22 +118,22 @@ b: {}'''), }); group('uuid', () { - var uuidRegexp = RegExp('^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-' + final uuidRegexp = RegExp('^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-' r'[8-9A-B][0-9A-F]{3}-[0-9A-F]{12}$'); test('min value is valid', () { - var uuid = createUuid(List.filled(16, 0)); + final uuid = createUuid(List.filled(16, 0)); expect(uuid, matches(uuidRegexp)); expect(uuid, '00000000-0000-4000-8000-000000000000'); }); test('max value is valid', () { - var uuid = createUuid(List.filled(16, 255)); + final uuid = createUuid(List.filled(16, 255)); expect(uuid, matches(uuidRegexp)); expect(uuid, 'FFFFFFFF-FFFF-4FFF-BFFF-FFFFFFFFFFFF'); }); test('random values are valid', () { for (var i = 0; i < 100; i++) { - var uuid = createUuid(); + final uuid = createUuid(); expect(uuid, matches(uuidRegexp)); } }); diff --git a/test/validator/directory_test.dart b/test/validator/directory_test.dart index 47fe82249..c58002bb3 100644 --- a/test/validator/directory_test.dart +++ b/test/validator/directory_test.dart @@ -43,7 +43,7 @@ void main() { 'named', () { setUp(d.validPackage().create); - var names = [ + final names = [ 'benchmarks', 'docs', 'examples', diff --git a/test/validator/flutter_plugin_format_test.dart b/test/validator/flutter_plugin_format_test.dart index 0a5bd4cba..5b6fcb4cc 100644 --- a/test/validator/flutter_plugin_format_test.dart +++ b/test/validator/flutter_plugin_format_test.dart @@ -20,7 +20,7 @@ void main() { }); test('is a Flutter 1.9.0 package', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -31,7 +31,7 @@ void main() { }); test('is a Flutter 1.10.0 package', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -42,7 +42,7 @@ void main() { }); test('is a Flutter 1.10.0-0 package', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -53,7 +53,7 @@ void main() { }); test('is a flutter 1.10.0 plugin with the new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -76,7 +76,7 @@ void main() { group('should consider a package invalid if it', () { test('is a flutter plugin with old and new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -107,7 +107,7 @@ void main() { }); test('is a flutter 1.9.0 plugin with old format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -130,7 +130,7 @@ void main() { }); test('is a flutter 1.9.0 plugin with new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -160,7 +160,7 @@ void main() { test( 'is a flutter plugin with only implicit flutter sdk version constraint and the new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -187,7 +187,7 @@ void main() { }); test('is a non-flutter package with using the new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', {}, {}, { + final pkg = packageMap('test_pkg', '1.0.0', {}, {}, { 'sdk': '>=2.0.0 <3.0.0', }); pkg['flutter'] = { @@ -212,7 +212,7 @@ void main() { }); test('is a flutter 1.8.0 plugin with new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', @@ -240,7 +240,7 @@ void main() { }); test('is a flutter 1.9.999 plugin with new format', () async { - var pkg = packageMap('test_pkg', '1.0.0', { + final pkg = packageMap('test_pkg', '1.0.0', { 'flutter': {'sdk': 'flutter'}, }, {}, { 'sdk': '>=2.0.0 <3.0.0', diff --git a/test/validator/license_test.dart b/test/validator/license_test.dart index 70b6b7ba8..474984ec0 100644 --- a/test/validator/license_test.dart +++ b/test/validator/license_test.dart @@ -73,7 +73,7 @@ void main() { }); test('has a .gitignored LICENSE file', () async { - var repo = d.git(appPath, [d.file('.gitignore', 'LICENSE')]); + final repo = d.git(appPath, [d.file('.gitignore', 'LICENSE')]); await d.validPackage().create(); await repo.create(); await expectValidationDeprecated(license, errors: isNotEmpty); diff --git a/test/validator/pubspec_field_test.dart b/test/validator/pubspec_field_test.dart index 694cb4712..908167fd2 100644 --- a/test/validator/pubspec_field_test.dart +++ b/test/validator/pubspec_field_test.dart @@ -19,7 +19,7 @@ void main() { test('looks normal', () => expectValidationDeprecated(pubspecField)); test('has an HTTPS homepage URL', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['homepage'] = 'https://pub.dev'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -27,7 +27,7 @@ void main() { }); test('has an HTTPS repository URL instead of homepage', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg.remove('homepage'); pkg['repository'] = 'https://pub.dev'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -36,7 +36,7 @@ void main() { }); test('has an HTTPS documentation URL', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['documentation'] = 'https://pub.dev'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -44,7 +44,7 @@ void main() { }); test('has empty executables', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['executables'] = {}; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -52,7 +52,7 @@ void main() { }); test('has executables', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['executables'] = { 'test_pkg': null, 'test_pkg_helper': 'helper', @@ -66,7 +66,7 @@ void main() { group('should warn if a package', () { test('is missing both the "homepage" and the "description" field', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg.remove('homepage'); await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -78,7 +78,7 @@ void main() { setUp(d.validPackage().create); test('is missing the "description" field', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg.remove('description'); await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -86,7 +86,7 @@ void main() { }); test('has a non-string "homepage" field', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['homepage'] = 12; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -94,7 +94,7 @@ void main() { }); test('has a non-string "repository" field', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['repository'] = 12; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -102,7 +102,7 @@ void main() { }); test('has a non-string "description" field', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['description'] = 12; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -110,7 +110,7 @@ void main() { }); test('has a non-HTTP homepage URL', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['homepage'] = 'file:///foo/bar'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -118,7 +118,7 @@ void main() { }); test('has a non-HTTP documentation URL', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['documentation'] = 'file:///foo/bar'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -126,7 +126,7 @@ void main() { }); test('has a non-HTTP repository URL', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['repository'] = 'file:///foo/bar'; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -134,7 +134,7 @@ void main() { }); test('has invalid executables', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['executables'] = ['wrong-thing']; await d.dir(appPath, [d.pubspec(pkg)]).create(); @@ -142,7 +142,7 @@ void main() { }); test('has invalid executables mapping to a number', () async { - var pkg = packageMap('test_pkg', '1.0.0'); + final pkg = packageMap('test_pkg', '1.0.0'); pkg['executables'] = { 'test_pkg': 33, }; diff --git a/test/validator/pubspec_test.dart b/test/validator/pubspec_test.dart index 995f3767f..480033ee6 100644 --- a/test/validator/pubspec_test.dart +++ b/test/validator/pubspec_test.dart @@ -18,7 +18,7 @@ void main() { test('should consider a package invalid if it has a .gitignored pubspec', () async { - var repo = d.git(appPath, [d.file('.gitignore', 'pubspec.yaml')]); + final repo = d.git(appPath, [d.file('.gitignore', 'pubspec.yaml')]); await d.validPackage().create(); await repo.create(); diff --git a/test/validator/readme_test.dart b/test/validator/readme_test.dart index 90df3a151..499c7eeea 100644 --- a/test/validator/readme_test.dart +++ b/test/validator/readme_test.dart @@ -31,7 +31,7 @@ void main() { test('has a gitignored README with invalid utf-8', () async { await d.validPackage().create(); - var repo = d.git(appPath, [ + final repo = d.git(appPath, [ d.file('README', [192]), d.file('.gitignore', 'README'), ]); diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart index bf3a4e090..8aa3e7aa6 100644 --- a/test/version_solver_test.dart +++ b/test/version_solver_test.dart @@ -480,7 +480,7 @@ Because myapp depends on foo ^1.0.0 which doesn't match any versions, version so }); test('mismatched descriptions', () async { - var otherServer = await startPackageServer(); + final otherServer = await startPackageServer(); otherServer.serve('shared', '1.0.0'); await servePackages() @@ -903,7 +903,7 @@ void backtracking() { // Like the above test, but for a conflicting description. test('successful backjump to conflicting description', () async { - var otherServer = await startPackageServer(); + final otherServer = await startPackageServer(); otherServer.serve('a', '1.0.0'); await servePackages() @@ -959,7 +959,7 @@ void backtracking() { }); test('failing backjump to conflicting description', () async { - var otherServer = await startPackageServer(); + final otherServer = await startPackageServer(); otherServer.serve('a', '1.0.0'); await servePackages() @@ -1978,20 +1978,20 @@ Future expectResolves({ if (result == null) return; - var cache = SystemCache(); - var registry = cache.sources; - var lockFile = + final cache = SystemCache(); + final registry = cache.sources; + final lockFile = LockFile.load(p.join(d.sandbox, appPath, 'pubspec.lock'), registry); - var resultPubspec = Pubspec.fromMap( + final resultPubspec = Pubspec.fromMap( {'dependencies': result}, registry, containingDescription: RootDescription('.'), ); - var ids = {...lockFile.packages}; + final ids = {...lockFile.packages}; for (var dep in resultPubspec.dependencies.values) { expect(ids, contains(dep.name)); - var id = ids.remove(dep.name)!; + final id = ids.remove(dep.name)!; final description = dep.description; if (description is HostedDescription && (description.url == SystemCache().hosted.defaultUrl)) { diff --git a/tool/extract_all_pub_dev.dart b/tool/extract_all_pub_dev.dart index 9525a1998..a61fcaa82 100644 --- a/tool/extract_all_pub_dev.dart +++ b/tool/extract_all_pub_dev.dart @@ -20,7 +20,7 @@ import 'package:pub/src/log.dart' as log; const statusFilename = 'extract_all_pub_status.json'; Future> allPackageNames() async { - var nextUrl = Uri.https('pub.dev', 'api/packages', {'compact': '1'}); + final nextUrl = Uri.https('pub.dev', 'api/packages', {'compact': '1'}); final request = http.Request('GET', nextUrl); request.attachMetadataHeaders(); final response = await globalHttpClient.fetch(request); @@ -40,8 +40,8 @@ Future> versionArchiveUrls(String packageName) async { } Future main() async { - var alreadyDonePackages = {}; - var failures = ?>[]; + final alreadyDonePackages = {}; + final failures = ?>[]; if (fileExists(statusFilename)) { final json = jsonDecode(readTextFile(statusFilename)); for (final packageName in json['packages'] as Iterable? ?? []) {