Upgrade package:lints to 2.0.0 (#3445)
diff --git a/lib/src/authentication/credential.dart b/lib/src/authentication/credential.dart
index e1dfc79..010d3f3 100644
--- a/lib/src/authentication/credential.dart
+++ b/lib/src/authentication/credential.dart
@@ -58,7 +58,7 @@
/// doesn't contains [key].
///
/// Throws [FormatException] if value type is not [String].
- String? _string(String key) {
+ String? string(String key) {
if (json.containsKey(key)) {
if (json[key] is! String) {
throw FormatException('Provided $key value should be string');
@@ -71,8 +71,8 @@
return Credential._internal(
url: hostedUrl,
unknownFields: unknownFields,
- token: _string('token'),
- env: _string('env'),
+ token: string('token'),
+ env: string('env'),
);
}
diff --git a/lib/src/authentication/token_store.dart b/lib/src/authentication/token_store.dart
index 3ef948d..fbb208a 100644
--- a/lib/src/authentication/token_store.dart
+++ b/lib/src/authentication/token_store.dart
@@ -112,31 +112,31 @@
/// Adds [token] into store and writes into disk.
void addCredential(Credential token) {
- final _credentials = _loadCredentials();
+ final credentials = _loadCredentials();
// Remove duplicate tokens
- _credentials.removeWhere((it) => it.url == token.url);
- _credentials.add(token);
- _saveCredentials(_credentials);
+ credentials.removeWhere((it) => it.url == token.url);
+ credentials.add(token);
+ _saveCredentials(credentials);
}
/// Removes tokens with matching [hostedUrl] from store. Returns whether or
/// not there's a stored token with matching url.
bool removeCredential(Uri hostedUrl) {
- final _credentials = _loadCredentials();
+ final credentials = _loadCredentials();
var i = 0;
var found = false;
- while (i < _credentials.length) {
- if (_credentials[i].url == hostedUrl) {
- _credentials.removeAt(i);
+ while (i < credentials.length) {
+ if (credentials[i].url == hostedUrl) {
+ credentials.removeAt(i);
found = true;
} else {
i++;
}
}
- _saveCredentials(_credentials);
+ _saveCredentials(credentials);
return found;
}
diff --git a/lib/src/command.dart b/lib/src/command.dart
index 240a15e..a1a8a2e 100644
--- a/lib/src/command.dart
+++ b/lib/src/command.dart
@@ -298,7 +298,7 @@
///
/// For top-level commands, if an alias is used, the primary command name is
/// returned. For instance `install` becomes `get`.
- static late final String command = _command ?? '';
+ static final String command = _command ?? '';
static void computeCommand(ArgResults argResults) {
var list = <String?>[];
diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart
index 196a7d6..d4c98ef 100644
--- a/lib/src/command/add.dart
+++ b/lib/src/command/add.dart
@@ -291,7 +291,7 @@
/// If any of the other git options are defined when `--git-url` is not
/// defined, an error will be thrown.
_ParseResult _parsePackage(String package, LanguageVersion languageVersion) {
- final _conflictingFlagSets = [
+ final conflictingFlagSets = [
['git-url', 'git-ref', 'git-path'],
['hosted-url'],
['path'],
@@ -299,8 +299,8 @@
];
for (final flag
- in _conflictingFlagSets.expand((s) => s).where(argResults.wasParsed)) {
- final conflictingFlag = _conflictingFlagSets
+ in conflictingFlagSets.expand((s) => s).where(argResults.wasParsed)) {
+ final conflictingFlag = conflictingFlagSets
.where((s) => !s.contains(flag))
.expand((s) => s)
.firstWhereOrNull(argResults.wasParsed);
diff --git a/lib/src/command/cache_repair.dart b/lib/src/command/cache_repair.dart
index 850b782..a4dccab 100644
--- a/lib/src/command/cache_repair.dart
+++ b/lib/src/command/cache_repair.dart
@@ -66,10 +66,10 @@
if (globalRepairResults.last.isNotEmpty) {
var packages = pluralize('package', globalRepairResults.last.length);
log.message(
- 'Failed to reactivate ${log.red(globalRepairResults.last.length)} $packages:\n' +
- globalRepairResults.last
- .map((name) => '- ${log.bold(name)}')
- .join('\n'));
+ 'Failed to reactivate ${log.red(globalRepairResults.last.length)} $packages:');
+ log.message(globalRepairResults.last
+ .map((name) => '- ${log.bold(name)}')
+ .join('\n'));
}
if (successes.isEmpty && failures.isEmpty) {
diff --git a/lib/src/command/dependency_services.dart b/lib/src/command/dependency_services.dart
index 5b252ae..193f345 100644
--- a/lib/src/command/dependency_services.dart
+++ b/lib/src/command/dependency_services.dart
@@ -72,7 +72,7 @@
final dependencies = <Object>[];
final result = <String, Object>{'dependencies': dependencies};
- Future<List<Object>> _computeUpgradeSet(
+ Future<List<Object>> computeUpgradeSet(
Pubspec rootPubspec,
PackageId? package, {
required _UpgradeType upgradeType,
@@ -203,15 +203,15 @@
?.versionOrHash(),
'constraint':
_constraintOf(compatiblePubspec, package.name)?.toString(),
- 'compatible': await _computeUpgradeSet(
+ 'compatible': await computeUpgradeSet(
compatiblePubspec, compatibleVersion,
upgradeType: _UpgradeType.compatible),
'singleBreaking': kind != 'transitive' && singleBreakingVersion == null
? []
- : await _computeUpgradeSet(compatiblePubspec, singleBreakingVersion,
+ : await computeUpgradeSet(compatiblePubspec, singleBreakingVersion,
upgradeType: _UpgradeType.singleBreaking),
'multiBreaking': kind != 'transitive' && multiBreakingVersion != null
- ? await _computeUpgradeSet(compatiblePubspec, multiBreakingVersion,
+ ? await computeUpgradeSet(compatiblePubspec, multiBreakingVersion,
upgradeType: _UpgradeType.multiBreaking)
: [],
});
diff --git a/lib/src/command/lish.dart b/lib/src/command/lish.dart
index 092fcaf..69c1c7e 100644
--- a/lib/src/command/lish.dart
+++ b/lib/src/command/lish.dart
@@ -133,7 +133,7 @@
' pub token add $host\n';
}
if (error.serverMessage != null) {
- msg += '\n' + error.serverMessage! + '\n';
+ msg += '\n${error.serverMessage!}\n';
}
dataError(msg + log.red('Authentication failed!'));
} on PubHttpException catch (error) {
diff --git a/lib/src/command/outdated.dart b/lib/src/command/outdated.dart
index 5c275e4..601bdc8 100644
--- a/lib/src/command/outdated.dart
+++ b/lib/src/command/outdated.dart
@@ -114,7 +114,7 @@
@override
Future<void> runProtected() async {
- final mode = <String, Mode>{
+ final mode = <String, _Mode>{
'outdated': _OutdatedMode(),
'null-safety': _NullSafetyMode(cache, entrypoint,
shouldShowSpinner: _shouldShowSpinner),
@@ -385,7 +385,7 @@
Future<void> _outputJson(
List<_PackageDetails> rows,
- Mode mode, {
+ _Mode mode, {
required bool showAll,
required bool includeDevDependencies,
}) async {
@@ -422,7 +422,7 @@
Future<void> _outputHuman(
List<_PackageDetails> rows,
- Mode mode, {
+ _Mode mode, {
required bool showAll,
required bool useColors,
required bool includeDevDependencies,
@@ -435,7 +435,7 @@
required String directory,
}) async {
final directoryDesc = directory == '.' ? '' : ' in $directory';
- log.message(mode.explanation(directoryDesc) + '\n');
+ log.message('${mode.explanation(directoryDesc)}\n');
final markedRows =
Map.fromIterables(rows, await mode.markVersionDetails(rows));
@@ -596,7 +596,7 @@
}
}
-abstract class Mode {
+abstract class _Mode {
/// Analyzes the [_PackageDetails] according to a --mode and outputs a
/// corresponding list of the versions
/// [current, upgradable, resolvable, latest].
@@ -613,7 +613,7 @@
Future<Pubspec> resolvablePubspec(Pubspec pubspec);
}
-class _OutdatedMode implements Mode {
+class _OutdatedMode implements _Mode {
@override
String explanation(String directoryDescription) => '''
Showing outdated packages$directoryDescription.
@@ -690,7 +690,7 @@
}
}
-class _NullSafetyMode implements Mode {
+class _NullSafetyMode implements _Mode {
final SystemCache cache;
final Entrypoint entrypoint;
final bool shouldShowSpinner;
diff --git a/lib/src/command/upgrade.dart b/lib/src/command/upgrade.dart
index af0c6e1..d6043c3 100644
--- a/lib/src/command/upgrade.dart
+++ b/lib/src/command/upgrade.dart
@@ -470,7 +470,7 @@
final hasNoNullSafetyVersions = <String>{};
final hasNullSafetyVersions = <String>{};
- Future<Iterable<PackageRange>> _removeUpperConstraints(
+ Future<Iterable<PackageRange>> removeUpperConstraints(
Iterable<PackageRange> dependencies,
) async =>
await Future.wait(dependencies.map((dep) async {
@@ -500,8 +500,8 @@
return dep.toRef().withConstraint(VersionConstraint.empty);
}));
- final deps = _removeUpperConstraints(original.dependencies.values);
- final devDeps = _removeUpperConstraints(original.devDependencies.values);
+ final deps = removeUpperConstraints(original.dependencies.values);
+ final devDeps = removeUpperConstraints(original.devDependencies.values);
await Future.wait([deps, devDeps]);
if (hasNoNullSafetyVersions.isNotEmpty) {
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index c17d7e8..3a51b2f 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -51,7 +51,7 @@
// sdks:
// dart: ">=1.2.3 <2.0.0"
// ```
- var sdkNames = sdks.keys.map((name) => ' ' + name).join('|');
+ var sdkNames = sdks.keys.map((name) => ' $name').join('|');
return RegExp(r'^(' + sdkNames + r'|sdk): "?([^"]*)"?$', multiLine: true);
}();
diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart
index 81c34f5..8bfe7cf 100644
--- a/lib/src/global_packages.dart
+++ b/lib/src/global_packages.dart
@@ -777,12 +777,12 @@
invocation = '''
if [ -f $snapshot ]; then
dart "$snapshot" "\$@"
- # The VM exits with code 253 if the snapshot version is out-of-date.
- # If it is, we need to delete it and run "pub global" manually.
- exit_code=\$?
- if [ \$exit_code != 253 ]; then
- exit \$exit_code
- fi
+ # The VM exits with code 253 if the snapshot version is out-of-date.
+ # If it is, we need to delete it and run "pub global" manually.
+ exit_code=\$?
+ if [ \$exit_code != 253 ]; then
+ exit \$exit_code
+ fi
dart pub global run ${package.name}:$script "\$@"
else
dart pub global run ${package.name}:$script "\$@"
@@ -858,7 +858,7 @@
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']);
+ var result = runProcessSync('where', [r'\q', '$installed.bat']);
if (result.exitCode == 0) return;
log.warning("${log.yellow('Warning:')} Pub installs executables into "
diff --git a/lib/src/io.dart b/lib/src/io.dart
index 0b382d1..6422f84 100644
--- a/lib/src/io.dart
+++ b/lib/src/io.dart
@@ -702,7 +702,7 @@
/// [environment] is provided, that will be used to augment (not replace) the
/// the inherited variables.
@visibleForTesting
-Future<_PubProcess> startProcess(
+Future<PubProcess> startProcess(
String executable,
List<String> args, {
String? workingDir,
@@ -721,7 +721,7 @@
'Pub failed to run subprocess `$executable`: $e');
}
- var process = _PubProcess(ioProcess);
+ var process = PubProcess(ioProcess);
unawaited(process.exitCode.whenComplete(resource.release));
return process;
});
@@ -752,7 +752,7 @@
}
/// A wrapper around [Process] that exposes `dart:async`-style APIs.
-class _PubProcess {
+class PubProcess {
/// The underlying `dart:io` [Process].
final Process _process;
@@ -811,8 +811,8 @@
/// error handler unless nothing has handled it.
Future<int> get exitCode => _exitCode;
- /// Creates a new [_PubProcess] wrapping [process].
- _PubProcess(Process process) : _process = process {
+ /// Creates a new [PubProcess] wrapping [process].
+ PubProcess(Process process) : _process = process {
var errorGroup = ErrorGroup();
var pair = _consumerToSink(process.stdin);
diff --git a/lib/src/lock_file.dart b/lib/src/lock_file.dart
index 0950de1..215ab92 100644
--- a/lib/src/lock_file.dart
+++ b/lib/src/lock_file.dart
@@ -224,7 +224,7 @@
String? relativeFrom,
}) {
var header = '''
-This file is deprecated. Tools should instead consume
+This file is deprecated. Tools should instead consume
`.dart_tool/package_config.json`.
For more info see: https://dart.dev/go/dot-packages-deprecation
@@ -305,7 +305,7 @@
generatorVersion: sdk.version,
);
- return JsonEncoder.withIndent(' ').convert(packageConfig.toJson()) + '\n';
+ return '${JsonEncoder.withIndent(' ').convert(packageConfig.toJson())}\n';
}
/// Returns the serialized YAML text of the lock file.
diff --git a/lib/src/package_config.dart b/lib/src/package_config.dart
index d64808b..e5e5e7d 100644
--- a/lib/src/package_config.dart
+++ b/lib/src/package_config.dart
@@ -61,21 +61,23 @@
}
final root = data;
- void _throw(String property, String mustBe) => throw FormatException(
- '"$property" in .dart_tool/package_config.json $mustBe');
+ void throwFormatException(String property, String mustBe) =>
+ throw FormatException(
+ '"$property" in .dart_tool/package_config.json $mustBe');
/// Read the 'configVersion' property
final configVersion = root['configVersion'];
if (configVersion is! int) {
- _throw('configVersion', 'must be an integer');
+ throwFormatException('configVersion', 'must be an integer');
}
if (configVersion != 2) {
- _throw('configVersion', 'must be 2 (the only supported version)');
+ throwFormatException(
+ 'configVersion', 'must be 2 (the only supported version)');
}
final packagesRaw = root['packages'];
if (packagesRaw is! List) {
- _throw('packages', 'must be a list');
+ throwFormatException('packages', 'must be a list');
}
final packages = <PackageConfigEntry>[];
for (final entry in packagesRaw) {
@@ -87,7 +89,7 @@
final generatedRaw = root['generated'];
if (generatedRaw != null) {
if (generatedRaw is! String) {
- _throw('generated', 'must be a string, if given');
+ throwFormatException('generated', 'must be a string, if given');
}
generated = DateTime.parse(generatedRaw);
}
@@ -104,12 +106,12 @@
final generatorVersionRaw = root['generatorVersion'];
if (generatorVersionRaw != null) {
if (generatorVersionRaw is! String) {
- _throw('generatorVersion', 'must be a string, if given');
+ throwFormatException('generatorVersion', 'must be a string, if given');
}
try {
generatorVersion = Version.parse(generatorVersionRaw);
} on FormatException catch (e) {
- _throw('generatorVersion',
+ throwFormatException('generatorVersion',
'must be a semver version, if given, error: ${e.message}');
}
}
@@ -187,30 +189,31 @@
}
final root = data;
- Never _throw(String property, String mustBe) => throw FormatException(
- '"packages[].$property" in .dart_tool/package_config.json $mustBe');
+ Never throwFormatException(String property, String mustBe) =>
+ throw FormatException(
+ '"packages[].$property" in .dart_tool/package_config.json $mustBe');
final name = root['name'];
if (name is! String) {
- _throw('name', 'must be a string');
+ throwFormatException('name', 'must be a string');
}
final Uri rootUri;
final rootUriRaw = root['rootUri'];
if (rootUriRaw is! String) {
- _throw('rootUri', 'must be a string');
+ throwFormatException('rootUri', 'must be a string');
}
try {
rootUri = Uri.parse(rootUriRaw);
} on FormatException {
- _throw('rootUri', 'must be a URI');
+ throwFormatException('rootUri', 'must be a URI');
}
Uri? packageUri;
var packageUriRaw = root['packageUri'];
if (packageUriRaw != null) {
if (packageUriRaw is! String) {
- _throw('packageUri', 'must be a string');
+ throwFormatException('packageUri', 'must be a string');
}
if (!packageUriRaw.endsWith('/')) {
packageUriRaw = '$packageUriRaw/';
@@ -218,7 +221,7 @@
try {
packageUri = Uri.parse(packageUriRaw);
} on FormatException {
- _throw('packageUri', 'must be a URI');
+ throwFormatException('packageUri', 'must be a URI');
}
}
@@ -226,12 +229,13 @@
final languageVersionRaw = root['languageVersion'];
if (languageVersionRaw != null) {
if (languageVersionRaw is! String) {
- _throw('languageVersion', 'must be a string');
+ throwFormatException('languageVersion', 'must be a string');
}
try {
languageVersion = LanguageVersion.parse(languageVersionRaw);
} on FormatException {
- _throw('languageVersion', 'must be on the form <major>.<minor>');
+ throwFormatException(
+ 'languageVersion', 'must be on the form <major>.<minor>');
}
}
diff --git a/lib/src/packages_file.dart b/lib/src/packages_file.dart
index 6833ae8..d5c7989 100644
--- a/lib/src/packages_file.dart
+++ b/lib/src/packages_file.dart
@@ -80,7 +80,7 @@
packageLocation = baseLocation.resolve(packageValue);
if (!packageLocation.path.endsWith('/')) {
packageLocation =
- packageLocation.replace(path: packageLocation.path + "/");
+ packageLocation.replace(path: "${packageLocation.path}/");
}
}
if (result.containsKey(packageName)) {
@@ -162,7 +162,7 @@
uri = _relativize(uri, baseUri);
}
if (!uri.path.endsWith('/')) {
- uri = uri.replace(path: uri.path + '/');
+ uri = uri.replace(path: '${uri.path}/');
}
output.write(uri);
output.writeln();
@@ -251,7 +251,7 @@
}
assert(badIndex < packageName.length);
var badCharCode = packageName.codeUnitAt(badIndex);
- var badChar = "U+" + badCharCode.toRadixString(16).padLeft(4, '0');
+ var badChar = "U+${badCharCode.toRadixString(16).padLeft(4, '0')}";
if (badCharCode >= 0x20 && badCharCode <= 0x7e) {
// Printable character.
badChar = "'${packageName[badIndex]}' ($badChar)";
diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart
index e18fbc6..d06b025 100644
--- a/lib/src/pubspec.dart
+++ b/lib/src/pubspec.dart
@@ -86,8 +86,7 @@
/// The registry of sources to use when parsing [dependencies] and
/// [devDependencies].
///
- /// This will be null if this was created using [new Pubspec] or [new
- /// Pubspec.empty].
+ /// This will be null if this was created using [Pubspec] or [Pubspec.empty].
final SourceRegistry _sources;
/// The location from which the pubspec was loaded.
@@ -431,7 +430,7 @@
/// This will return at most one error for each field.
List<PubspecException> get allErrors {
var errors = <PubspecException>[];
- void _collectError(void Function() fn) {
+ void collectError(void Function() fn) {
try {
fn();
} on PubspecException catch (e) {
@@ -439,14 +438,14 @@
}
}
- _collectError(() => name);
- _collectError(() => version);
- _collectError(() => dependencies);
- _collectError(() => devDependencies);
- _collectError(() => publishTo);
- _collectError(() => executables);
- _collectError(() => falseSecrets);
- _collectError(_ensureEnvironment);
+ collectError(() => name);
+ collectError(() => version);
+ collectError(() => dependencies);
+ collectError(() => devDependencies);
+ collectError(() => publishTo);
+ collectError(() => executables);
+ collectError(() => falseSecrets);
+ collectError(_ensureEnvironment);
return errors;
}
}
diff --git a/lib/src/pubspec_parse.dart b/lib/src/pubspec_parse.dart
index 68f9ce7..62eaa13 100644
--- a/lib/src/pubspec_parse.dart
+++ b/lib/src/pubspec_parse.dart
@@ -136,7 +136,7 @@
final falseSecrets = <String>[];
// Throws a [PubspecException]
- void _falseSecretsError(SourceSpan span) => _error(
+ void falseSecretsError(SourceSpan span) => _error(
'"false_secrets" field must be a list of git-ignore style patterns',
span,
);
@@ -147,12 +147,12 @@
for (final node in falseSecretsNode.nodes) {
final value = node.value;
if (value is! String) {
- _falseSecretsError(node.span);
+ falseSecretsError(node.span);
}
falseSecrets.add(value);
}
} else {
- _falseSecretsError(falseSecretsNode.span);
+ falseSecretsError(falseSecretsNode.span);
}
}
diff --git a/lib/src/pubspec_utils.dart b/lib/src/pubspec_utils.dart
index cd28e21..71e30c4 100644
--- a/lib/src/pubspec_utils.dart
+++ b/lib/src/pubspec_utils.dart
@@ -108,7 +108,7 @@
ArgumentError.checkNotNull(original, 'original');
stripOnly ??= [];
- List<PackageRange> _stripUpperBounds(
+ List<PackageRange> stripUpperBounds(
Map<String, PackageRange> constrained,
) {
final result = <PackageRange>[];
@@ -133,8 +133,8 @@
original.name,
version: original.version,
sdkConstraints: original.sdkConstraints,
- dependencies: _stripUpperBounds(original.dependencies),
- devDependencies: _stripUpperBounds(original.devDependencies),
+ dependencies: stripUpperBounds(original.dependencies),
+ devDependencies: stripUpperBounds(original.devDependencies),
dependencyOverrides: original.dependencyOverrides.values,
);
}
diff --git a/lib/src/rate_limited_scheduler.dart b/lib/src/rate_limited_scheduler.dart
index 85d73cd..078acbb 100644
--- a/lib/src/rate_limited_scheduler.dart
+++ b/lib/src/rate_limited_scheduler.dart
@@ -110,7 +110,7 @@
return await callback((jobId) {
if (_started.contains(jobId)) return;
final task = _Task(jobId, Zone.current);
- _cache.putIfAbsent(jobId, () => Completer());
+ _cache.putIfAbsent(jobId, Completer.new);
_queue.addLast(task);
prescheduled.add(task);
@@ -127,7 +127,7 @@
/// If [jobId] is not yet running, it will go to the front of the work queue
/// to be scheduled next when there are free resources.
Future<V> schedule(J jobId) {
- final completer = _cache.putIfAbsent(jobId, () => Completer());
+ final completer = _cache.putIfAbsent(jobId, Completer.new);
if (!_started.contains(jobId)) {
final task = _Task(jobId, Zone.current);
_queue.addFirst(task);
diff --git a/lib/src/solver/failure.dart b/lib/src/solver/failure.dart
index 23b2e2f..5af4015 100644
--- a/lib/src/solver/failure.dart
+++ b/lib/src/solver/failure.dart
@@ -201,12 +201,8 @@
var conflictLine = _lineNumbers[conflictClause.conflict];
var otherLine = _lineNumbers[conflictClause.other];
if (conflictLine != null && otherLine != null) {
- _write(
- incompatibility,
- 'Because ' +
- conflictClause.conflict.andToString(conflictClause.other,
- detailsForCause, conflictLine, otherLine) +
- ', $incompatibilityString.',
+ _write(incompatibility,
+ 'Because ${conflictClause.conflict.andToString(conflictClause.other, detailsForCause, conflictLine, otherLine)}, $incompatibilityString.',
numbered: numbered);
} else if (conflictLine != null || otherLine != null) {
Incompatibility withLine;
@@ -264,11 +260,8 @@
var derivedLine = _lineNumbers[derived];
if (derivedLine != null) {
- _write(
- incompatibility,
- 'Because ' +
- ext.andToString(derived, detailsForCause, null, derivedLine) +
- ', $incompatibilityString.',
+ _write(incompatibility,
+ 'Because ${ext.andToString(derived, detailsForCause, null, derivedLine)}, $incompatibilityString.',
numbered: numbered);
} else if (_isCollapsible(derived)) {
var derivedCause = derived.cause as ConflictCause;
diff --git a/lib/src/solver/incompatibility.dart b/lib/src/solver/incompatibility.dart
index 9e39865..04c7c3f 100644
--- a/lib/src/solver/incompatibility.dart
+++ b/lib/src/solver/incompatibility.dart
@@ -126,7 +126,7 @@
if (!cause.sdk.isAvailable) {
buffer.write('the ${cause.sdk.name} SDK');
} else {
- if (cause.sdk.name != 'Dart') buffer.write(cause.sdk.name + ' ');
+ if (cause.sdk.name != 'Dart') buffer.write('${cause.sdk.name} ');
buffer.write('SDK version ${cause.constraint}');
}
return buffer.toString();
@@ -262,7 +262,7 @@
.join(' or ');
var buffer =
- StringBuffer(_terse(thisPositive, details, allowEvery: true) + ' ');
+ StringBuffer('${_terse(thisPositive, details, allowEvery: true)} ');
var isDependency = cause == IncompatibilityCause.dependency &&
other.cause == IncompatibilityCause.dependency;
buffer.write(isDependency ? 'depends on' : 'requires');
@@ -414,7 +414,7 @@
if (!cause.sdk.isAvailable) {
buffer.write('the ${cause.sdk.name} SDK');
} else {
- if (cause.sdk.name != 'Dart') buffer.write(cause.sdk.name + ' ');
+ if (cause.sdk.name != 'Dart') buffer.write('${cause.sdk.name} ');
buffer.write('SDK version ${cause.constraint}');
}
} else if (latter.cause == IncompatibilityCause.noVersions) {
diff --git a/lib/src/source/hosted.dart b/lib/src/source/hosted.dart
index f403c60..e7dc870 100644
--- a/lib/src/source/hosted.dart
+++ b/lib/src/source/hosted.dart
@@ -77,7 +77,7 @@
}
// If there is a path, and it doesn't end in a slash we normalize to slash
if (u.path.isNotEmpty && !u.path.endsWith('/')) {
- u = u.replace(path: u.path + '/');
+ u = u.replace(path: '${u.path}/');
}
// pub.dev and pub.dartlang.org are identical.
//
diff --git a/lib/src/source/sdk.dart b/lib/src/source/sdk.dart
index fe10eb4..da492f5 100644
--- a/lib/src/source/sdk.dart
+++ b/lib/src/source/sdk.dart
@@ -118,7 +118,7 @@
// [PackageNotFoundException]s are uncapitalized and unpunctuated because
// they're used within other sentences by the version solver, but
// [ApplicationException]s should be full sentences.
- throw ApplicationException(capitalize(error.message) + '.');
+ throw ApplicationException('${capitalize(error.message)}.');
}
}
}
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 2a5768e..3e1cf48 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -186,7 +186,7 @@
/// commas and/or [conjunction] (`"and"` by default) where appropriate.
String toSentence(Iterable iter, {String conjunction = 'and'}) {
if (iter.length == 1) return iter.first.toString();
- return iter.take(iter.length - 1).join(', ') + ' $conjunction ${iter.last}';
+ return '${iter.take(iter.length - 1).join(', ')} $conjunction ${iter.last}';
}
/// Returns [name] if [number] is 1, or the plural of [name] otherwise.
@@ -447,7 +447,7 @@
String yamlToString(data) {
var buffer = StringBuffer();
- void _stringify(bool isMapValue, String indent, data) {
+ void stringify(bool isMapValue, String indent, data) {
// TODO(nweiz): Serialize using the YAML library once it supports
// serialization.
@@ -473,7 +473,7 @@
}
buffer.write('$indent$keyString:');
- _stringify(true, indent, data[key]);
+ stringify(true, indent, data[key]);
}
return;
@@ -495,7 +495,7 @@
}
}
- _stringify(false, '', data);
+ stringify(false, '', data);
return buffer.toString();
}
diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart
index 40e9c2a..fa01b45 100644
--- a/lib/src/validator/dependency.dart
+++ b/lib/src/validator/dependency.dart
@@ -27,11 +27,11 @@
@override
Future validate() async {
/// Whether any dependency has a caret constraint.
- var _hasCaretDep = false;
+ var hasCaretDep = false;
/// Emit an error for dependencies from unknown SDKs or without appropriate
/// constraints on the Dart SDK.
- void _warnAboutSdkSource(PackageRange dep) {
+ void warnAboutSdkSource(PackageRange dep) {
var identifier = (dep.description as SdkDescription).sdk;
var sdk = sdks[identifier];
if (sdk == null) {
@@ -44,7 +44,7 @@
}
/// Warn that dependencies should use the hosted source.
- Future _warnAboutSource(PackageRange dep) async {
+ Future warnAboutSource(PackageRange dep) async {
List<Version> versions;
try {
var ids = await entrypoint.cache
@@ -78,9 +78,9 @@
}
/// Warn about improper dependencies on Flutter.
- void _warnAboutFlutterSdk(PackageRange dep) {
+ void warnAboutFlutterSdk(PackageRange dep) {
if (dep.source is SdkSource) {
- _warnAboutSdkSource(dep);
+ warnAboutSdkSource(dep);
return;
}
@@ -95,7 +95,7 @@
}
/// Warn that dependencies should have version constraints.
- void _warnAboutNoConstraint(PackageRange dep) {
+ void warnAboutNoConstraint(PackageRange dep) {
var message = 'Your dependency on "${dep.name}" should have a version '
'constraint.';
var locked = entrypoint.lockFile.packages[dep.name];
@@ -111,7 +111,7 @@
}
/// Warn that dependencies should allow more than a single version.
- void _warnAboutSingleVersionConstraint(PackageRange dep) {
+ void warnAboutSingleVersionConstraint(PackageRange dep) {
warnings.add(
'Your dependency on "${dep.name}" should allow more than one version. '
'For example:\n'
@@ -125,7 +125,7 @@
}
/// Warn that dependencies should have lower bounds on their constraints.
- void _warnAboutNoConstraintLowerBound(PackageRange dep) {
+ void warnAboutNoConstraintLowerBound(PackageRange dep) {
var message =
'Your dependency on "${dep.name}" should have a lower bound.';
var locked = entrypoint.lockFile.packages[dep.name];
@@ -148,7 +148,7 @@
}
/// Warn that dependencies should have upper bounds on their constraints.
- void _warnAboutNoConstraintUpperBound(PackageRange dep) {
+ void warnAboutNoConstraintUpperBound(PackageRange dep) {
String constraint;
if ((dep.constraint as VersionRange).includeMin) {
constraint = '^${(dep.constraint as VersionRange).min}';
@@ -169,7 +169,7 @@
'${log.bold("all")} future versions of ${dep.name}.');
}
- void _warnAboutPrerelease(String dependencyName, VersionRange constraint) {
+ void warnAboutPrerelease(String dependencyName, VersionRange constraint) {
final packageVersion = entrypoint.root.version;
if (constraint.min != null &&
constraint.min!.isPreRelease &&
@@ -184,15 +184,15 @@
}
/// Validates all dependencies in [dependencies].
- Future _validateDependencies(Iterable<PackageRange> dependencies) async {
+ Future validateDependencies(Iterable<PackageRange> dependencies) async {
for (var dependency in dependencies) {
var constraint = dependency.constraint;
if (dependency.name == 'flutter') {
- _warnAboutFlutterSdk(dependency);
+ warnAboutFlutterSdk(dependency);
} else if (dependency.source is SdkSource) {
- _warnAboutSdkSource(dependency);
+ warnAboutSdkSource(dependency);
} else if (dependency.source is! HostedSource) {
- await _warnAboutSource(dependency);
+ await warnAboutSource(dependency);
final description = dependency.description;
if (description is GitDescription && description.path != '.') {
@@ -201,28 +201,27 @@
}
} else {
if (constraint.isAny) {
- _warnAboutNoConstraint(dependency);
+ warnAboutNoConstraint(dependency);
} else if (constraint is VersionRange) {
if (constraint is Version) {
- _warnAboutSingleVersionConstraint(dependency);
+ warnAboutSingleVersionConstraint(dependency);
} else {
- _warnAboutPrerelease(dependency.name, constraint);
+ warnAboutPrerelease(dependency.name, constraint);
if (constraint.min == null) {
- _warnAboutNoConstraintLowerBound(dependency);
+ warnAboutNoConstraintLowerBound(dependency);
} else if (constraint.max == null) {
- _warnAboutNoConstraintUpperBound(dependency);
+ warnAboutNoConstraintUpperBound(dependency);
}
}
- _hasCaretDep =
- _hasCaretDep || constraint.toString().startsWith('^');
+ hasCaretDep = hasCaretDep || constraint.toString().startsWith('^');
}
}
}
}
- await _validateDependencies(entrypoint.root.pubspec.dependencies.values);
+ await validateDependencies(entrypoint.root.pubspec.dependencies.values);
- if (_hasCaretDep) {
+ if (hasCaretDep) {
validateSdkConstraint(_firstCaretVersion,
"Older versions of pub don't support ^ version constraints.");
}
diff --git a/pubspec.yaml b/pubspec.yaml
index f39e27a..e44e0e7 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,7 @@
name: pub
environment:
- sdk: '>=2.12.0 <3.0.0'
+ sdk: '>=2.17.0 <3.0.0'
dependencies:
# Note: Pub's test infrastructure assumes that any dependencies used in tests
@@ -15,6 +15,7 @@
frontend_server_client: ^2.0.0
http: ^0.13.3
http_multi_server: ^3.0.1
+ http_parser: ^4.0.1
meta: ^1.3.0
oauth2: ^2.0.0
path: ^1.8.0
@@ -28,7 +29,7 @@
yaml_edit: ^2.0.0
dev_dependencies:
- lints: ^1.0.1
+ lints: ^2.0.0
shelf_test_handler: ^2.0.0
test: ^1.17.3
test_descriptor: ^2.0.0
diff --git a/test/dependency_services/dependency_services_test.dart b/test/dependency_services/dependency_services_test.dart
index 08542ea..7228b36 100644
--- a/test/dependency_services/dependency_services_test.dart
+++ b/test/dependency_services/dependency_services_test.dart
@@ -82,7 +82,7 @@
return filterUnstableLines(s.split('\n'));
}
-Future<void> listReportApply(
+Future<void> _listReportApply(
GoldenTestContext context,
List<_PackageVersion> upgrades, {
void Function(Map)? reportAssertions,
@@ -132,7 +132,7 @@
]).create();
await pubGet();
server.dontAllowDownloads();
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', '2.2.3'),
_PackageVersion('transitive', null)
], reportAssertions: (report) {
@@ -168,7 +168,7 @@
]).create();
server.dontAllowDownloads();
- await listReportApply(
+ await _listReportApply(
context,
[
_PackageVersion('foo', '2.2.3'),
@@ -201,7 +201,7 @@
server.dontAllowDownloads();
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', '1.2.4'),
], reportAssertions: (report) {
expect(
@@ -228,7 +228,7 @@
await pubGet();
server.dontAllowDownloads();
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', '2.2.3'),
_PackageVersion('transitive', '1.0.0')
], reportAssertions: (report) {
@@ -271,7 +271,7 @@
server.dontAllowDownloads();
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', '3.0.1',
constraint: VersionConstraint.parse('^3.0.0')),
_PackageVersion('bar', '2.0.0')
@@ -298,7 +298,7 @@
}).create();
await pubGet();
server.serve('foo', '2.0.0');
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', '2.0.0',
constraint: VersionConstraint.parse('^2.0.0')),
], reportAssertions: (report) {
@@ -331,7 +331,7 @@
final barSecondVersion = d.git('bar.git', [d.libPubspec('bar', '2.0.0')]);
await barSecondVersion.commit();
- await listReportApply(context, [
+ await _listReportApply(context, [
_PackageVersion('foo', newRef),
], reportAssertions: (report) {
expect(
diff --git a/test/descriptor/packages.dart b/test/descriptor/packages.dart
index b670322..e728f7c 100644
--- a/test/descriptor/packages.dart
+++ b/test/descriptor/packages.dart
@@ -133,7 +133,7 @@
final packageConfigFile = File(p.join(parent ?? sandbox, name));
await packageConfigFile.parent.create();
await packageConfigFile.writeAsString(
- const JsonEncoder.withIndent(' ').convert(_config.toJson()) + '\n',
+ '${const JsonEncoder.withIndent(' ').convert(_config.toJson())}\n',
);
}
diff --git a/test/embedding/get_executable_for_command_test.dart b/test/embedding/get_executable_for_command_test.dart
index 0edfa72..7f395a7 100644
--- a/test/embedding/get_executable_for_command_test.dart
+++ b/test/embedding/get_executable_for_command_test.dart
@@ -23,7 +23,7 @@
errorMessage,
CommandResolutionIssue? issue,
}) async {
- final _cachePath = getPubTestEnvironment()['PUB_CACHE'];
+ final cachePath = getPubTestEnvironment()['PUB_CACHE'];
final oldVerbosity = log.verbosity;
log.verbosity = log.Verbosity.none;
if (executable == null) {
@@ -31,7 +31,7 @@
() => getExecutableForCommand(
command,
root: root,
- pubCacheDir: _cachePath,
+ pubCacheDir: cachePath,
allowSnapshot: allowSnapshot,
),
throwsA(
@@ -44,7 +44,7 @@
final e = await getExecutableForCommand(
command,
root: root,
- pubCacheDir: _cachePath,
+ pubCacheDir: cachePath,
allowSnapshot: allowSnapshot,
);
expect(
diff --git a/test/golden_file.dart b/test/golden_file.dart
index b8b7eaa..c4baefe 100644
--- a/test/golden_file.dart
+++ b/test/golden_file.dart
@@ -60,7 +60,7 @@
'goldens',
rel,
// Sanitize the name, and add .txt
- _testName.replaceAll(RegExp(r'[<>:"/\|?*%#]'), '~') + '.txt',
+ '${_testName.replaceAll(RegExp(r'[<>:"/\|?*%#]'), '~')}.txt',
);
_goldenFile = File(_goldenFilePath);
_header = '# GENERATED BY: ${p.relative(_currentTestFile)}\n\n';
diff --git a/test/hosted/will_normalize_hosted_url_test.dart b/test/hosted/will_normalize_hosted_url_test.dart
index 6cc3888..904d3d8 100644
--- a/test/hosted/will_normalize_hosted_url_test.dart
+++ b/test/hosted/will_normalize_hosted_url_test.dart
@@ -42,7 +42,7 @@
await d.dir(appPath, [
d.appPubspec({
'foo': {
- 'hosted': {'name': 'foo', 'url': globalServer.url + '/'},
+ 'hosted': {'name': 'foo', 'url': '${globalServer.url}/'},
},
}),
]).create();
@@ -65,7 +65,7 @@
await d.dir(appPath, [
d.appPubspec({
'foo': {
- 'hosted': {'name': 'foo', 'url': globalServer.url + '//'},
+ 'hosted': {'name': 'foo', 'url': '${globalServer.url}//'},
},
}),
]).create();
@@ -81,7 +81,7 @@
///
/// This is a bit of a hack, to easily test if hosted pub URLs with a path
/// segment works and if the slashes are normalized.
- void _proxyMyFolderToRoot() {
+ void proxyMyFolderToRoot() {
globalServer.handle(
RegExp('/my-folder/.*'),
(r) async {
@@ -90,7 +90,7 @@
}
final path = r.requestedUri.path.substring('/my-folder/'.length);
final res = await http.get(
- Uri.parse(globalServer.url + '/$path'),
+ Uri.parse('${globalServer.url}/$path'),
);
return Response(res.statusCode, body: res.bodyBytes, headers: {
'Content-Type': res.headers['content-type']!,
@@ -102,11 +102,11 @@
test('will use normalized url with path', () async {
final server = await servePackages();
server.serve('foo', '1.2.3');
- _proxyMyFolderToRoot();
+ proxyMyFolderToRoot();
// testing with a normalized URL
- final testUrl = globalServer.url + '/my-folder/';
- final normalizedUrl = globalServer.url + '/my-folder/';
+ final testUrl = '${globalServer.url}/my-folder/';
+ final normalizedUrl = '${globalServer.url}/my-folder/';
await d.dir(appPath, [
d.appPubspec({
@@ -126,11 +126,11 @@
test('will normalize url with path by adding slash', () async {
final server = await servePackages();
server.serve('foo', '1.2.3');
- _proxyMyFolderToRoot();
+ proxyMyFolderToRoot();
// Testing with a URL that is missing the slash.
- final testUrl = globalServer.url + '/my-folder';
- final normalizedUrl = globalServer.url + '/my-folder/';
+ final testUrl = '${globalServer.url}/my-folder';
+ final normalizedUrl = '${globalServer.url}/my-folder/';
await d.dir(appPath, [
d.appPubspec({
diff --git a/test/ignore_test.dart b/test/ignore_test.dart
index a8ab8ac..9d80c5b 100644
--- a/test/ignore_test.dart
+++ b/test/ignore_test.dart
@@ -20,7 +20,7 @@
});
group('pub', () {
- void _testIgnorePath(
+ void testIgnorePath(
TestData c,
String path,
bool expected,
@@ -87,10 +87,10 @@
c.paths.forEach((path, expected) {
var ignoreCase = c.ignoreCase;
if (ignoreCase == null) {
- _testIgnorePath(c, path, expected, false);
- _testIgnorePath(c, path, expected, true);
+ testIgnorePath(c, path, expected, false);
+ testIgnorePath(c, path, expected, true);
} else {
- _testIgnorePath(c, path, expected, ignoreCase);
+ testIgnorePath(c, path, expected, ignoreCase);
}
});
}
@@ -124,7 +124,7 @@
runGit(['clean', '-f', '-d', '-x'], workingDirectory: tmp!.path);
});
- void _testIgnorePath(
+ void testIgnorePath(
TestData c,
String path,
bool expected,
@@ -144,12 +144,12 @@
for (final directory in c.patterns.keys) {
final resolvedDirectory =
- directory == '' ? tmp!.uri : tmp!.uri.resolve(directory + '/');
+ directory == '' ? tmp!.uri : tmp!.uri.resolve('$directory/');
Directory.fromUri(resolvedDirectory).createSync(recursive: true);
final gitIgnore =
File.fromUri(resolvedDirectory.resolve('.gitignore'));
gitIgnore.writeAsStringSync(
- c.patterns[directory]!.join('\n') + '\n',
+ '${c.patterns[directory]!.join('\n')}\n',
);
}
final process = runGit(
@@ -173,10 +173,10 @@
c.paths.forEach((path, expected) {
var ignoreCase = c.ignoreCase;
if (ignoreCase == null) {
- _testIgnorePath(c, path, expected, false);
- _testIgnorePath(c, path, expected, true);
+ testIgnorePath(c, path, expected, false);
+ testIgnorePath(c, path, expected, true);
} else {
- _testIgnorePath(c, path, expected, ignoreCase);
+ testIgnorePath(c, path, expected, ignoreCase);
}
});
}
diff --git a/test/lish/archives_and_uploads_a_package_test.dart b/test/lish/archives_and_uploads_a_package_test.dart
index b033e28..41db57c 100644
--- a/test/lish/archives_and_uploads_a_package_test.dart
+++ b/test/lish/archives_and_uploads_a_package_test.dart
@@ -67,7 +67,7 @@
await d.tokensFile({
'version': 1,
'hosted': [
- {'url': globalServer.url + '/sub/folder', 'env': 'TOKEN'},
+ {'url': '${globalServer.url}/sub/folder', 'env': 'TOKEN'},
]
}).create();
var pub = await startPublish(
diff --git a/test/package_server.dart b/test/package_server.dart
index 952c189..6aaea68 100644
--- a/test/package_server.dart
+++ b/test/package_server.dart
@@ -186,7 +186,7 @@
contents ??= [d.libDir(name, '$name $version')];
contents = [d.file('pubspec.yaml', yaml(pubspecFields)), ...contents];
- var package = _packages.putIfAbsent(name, () => _ServedPackage());
+ var package = _packages.putIfAbsent(name, _ServedPackage.new);
package.versions[version] = _ServedPackageVersion(
pubspecFields,
contents: () {
diff --git a/test/utils_test.dart b/test/utils_test.dart
index c416951..78ccbaf 100644
--- a/test/utils_test.dart
+++ b/test/utils_test.dart
@@ -128,7 +128,7 @@
test('is stable', () async {
{
final completers = <String, Completer>{};
- Completer completer(k) => completers.putIfAbsent(k, () => Completer());
+ Completer completer(k) => completers.putIfAbsent(k, Completer.new);
Future<int> lengthWhenComplete(String s) async {
await completer(s).future;
return s.length;
@@ -145,7 +145,7 @@
}
{
final completers = <String, Completer>{};
- Completer completer(k) => completers.putIfAbsent(k, () => Completer());
+ Completer completer(k) => completers.putIfAbsent(k, Completer.new);
Future<int> lengthWhenComplete(String s) async {
await completer(s).future;
return s.length;
diff --git a/test/validator/pubspec_test.dart b/test/validator/pubspec_test.dart
index ea0f5af..c7e1272 100644
--- a/test/validator/pubspec_test.dart
+++ b/test/validator/pubspec_test.dart
@@ -13,7 +13,7 @@
test('should consider a package valid if it has a pubspec', () async {
await d.validPackage.create();
- await expectValidation(() => PubspecValidator());
+ await expectValidation(PubspecValidator.new);
});
test('should consider a package invalid if it has a .gitignored pubspec',
@@ -22,6 +22,6 @@
await d.validPackage.create();
await repo.create();
- await expectValidation(() => PubspecValidator(), errors: isNotEmpty);
+ await expectValidation(PubspecValidator.new, errors: isNotEmpty);
});
}
diff --git a/test/validator/size_test.dart b/test/validator/size_test.dart
index ba5151d..0773bc1 100644
--- a/test/validator/size_test.dart
+++ b/test/validator/size_test.dart
@@ -13,7 +13,7 @@
Future<void> expectSizeValidationError(Matcher matcher) async {
await expectValidation(
- () => SizeValidator(),
+ SizeValidator.new,
size: 100 * (1 << 20) + 1,
errors: contains(matcher),
);
@@ -23,8 +23,8 @@
test('considers a package valid if it is <= 100 MB', () async {
await d.validPackage.create();
- await expectValidation(() => SizeValidator(), size: 100);
- await expectValidation(() => SizeValidator(), size: 100 * (1 << 20));
+ await expectValidation(SizeValidator.new, size: 100);
+ await expectValidation(SizeValidator.new, size: 100 * (1 << 20));
});
group('considers a package invalid if it is more than 100 MB', () {
diff --git a/tool/extract_all_pub_dev.dart b/tool/extract_all_pub_dev.dart
index f96dc5a..323c05c 100644
--- a/tool/extract_all_pub_dev.dart
+++ b/tool/extract_all_pub_dev.dart
@@ -84,7 +84,7 @@
.send(http.Request('GET', Uri.parse(archiveUrl)));
await extractTarGz(response.stream, tempDir);
print('Extracted $archiveUrl');
- } catch (e, _) {
+ } catch (e) {
print('Failed to get and extract $archiveUrl $e');
failures.add({'archive': archiveUrl, 'error': e.toString()});
allVersionsGood = false;
diff --git a/tool/test-bin/pub_command_runner.dart b/tool/test-bin/pub_command_runner.dart
index e438aae..3c1bef9 100644
--- a/tool/test-bin/pub_command_runner.dart
+++ b/tool/test-bin/pub_command_runner.dart
@@ -14,7 +14,7 @@
import 'package:pub/src/log.dart' as log;
import 'package:usage/usage.dart';
-final _LoggingAnalytics loggingAnalytics = _LoggingAnalytics();
+final Analytics loggingAnalytics = _LoggingAnalytics();
// A command for explicitly throwing an exception, to test the handling of
// unexpected eceptions.