Skip to content

Commit

Permalink
Migrate to language 3.7, reformat, upgrade (#4525)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored Feb 20, 2025
1 parent a7fb7f2 commit 639536a
Show file tree
Hide file tree
Showing 354 changed files with 10,667 additions and 10,861 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ linter:
- no_runtimeType_toString
- prefer_const_declarations
- prefer_final_locals
- require_trailing_commas
- unawaited_futures
- unreachable_from_main
- use_enums
10 changes: 5 additions & 5 deletions bin/dependency_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class _DependencyServicesCommandRunner extends CommandRunner<int>
}

_DependencyServicesCommandRunner()
: super(
'dependency_services',
'Support for automatic upgrades',
usageLineLength: lineLength,
) {
: super(
'dependency_services',
'Support for automatic upgrades',
usageLineLength: lineLength,
) {
argParser.addFlag(
'verbose',
abbr: 'v',
Expand Down
5 changes: 3 additions & 2 deletions lib/src/ascii_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ String fromFiles(
}
var directory = root;
for (var part in parts) {
directory = directory.putIfAbsent(part, () => <String, Map>{})
as Map<String, Map>;
directory =
directory.putIfAbsent(part, () => <String, Map>{})
as Map<String, Map>;
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/authentication/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class _AuthenticatedClient extends http.BaseClient {
if (response.headers.containsKey(HttpHeaders.wwwAuthenticateHeader)) {
try {
final header = response.headers[HttpHeaders.wwwAuthenticateHeader]!;
final challenge =
AuthenticationChallenge.parseHeader(header).firstWhereOrNull(
final challenge = AuthenticationChallenge.parseHeader(
header,
).firstWhereOrNull(
(challenge) =>
challenge.scheme == 'bearer' &&
challenge.parameters['realm'] == 'pub' &&
Expand Down
14 changes: 8 additions & 6 deletions lib/src/authentication/credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class Credential {

/// Create credential that stores clear text token.
Credential.token(this.url, this.token)
: env = null,
unknownFields = const <String, dynamic>{};
: env = null,
unknownFields = const <String, dynamic>{};

/// Create credential that stores environment variable name that stores token
/// value.
Credential.env(this.url, this.env)
: token = null,
unknownFields = const <String, dynamic>{};
: token = null,
unknownFields = const <String, dynamic>{};

/// Deserialize [json] into [Credential] type.
///
Expand Down Expand Up @@ -146,8 +146,10 @@ class Credential {
tokenValue = token!;
}
if (!isValidBearerToken(tokenValue)) {
dataError('Credential token for $url is not a valid Bearer token. '
'It should match `^[a-zA-Z0-9._~+/=-]+\$`');
dataError(
'Credential token for $url is not a valid Bearer token. '
'It should match `^[a-zA-Z0-9._~+/=-]+\$`',
);
}

return Future.value('Bearer $tokenValue');
Expand Down
25 changes: 15 additions & 10 deletions lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ abstract class PubCommand extends Command<int> {
/// Short description of how the arguments should be provided in `invocation`.
///
/// Override for giving a more detailed description.
String get argumentsDescription => subcommands.isEmpty
? '<subcommand> [arguments...]'
: (takesArguments ? '[arguments...]' : '');
String get argumentsDescription =>
subcommands.isEmpty
? '<subcommand> [arguments...]'
: (takesArguments ? '[arguments...]' : '');

/// If not `null` this overrides the default exit-code [exit_codes.SUCCESS]
/// when exiting successfully.
Expand Down Expand Up @@ -316,17 +317,20 @@ and attaching the relevant parts of that log file.
if (!argResults.wasParsed('color')) {
forceColors = ForceColorOption.auto;
} else {
forceColors = argResults.flag('color')
? ForceColorOption.always
: ForceColorOption.never;
forceColors =
argResults.flag('color')
? ForceColorOption.always
: ForceColorOption.never;
}
}

static void _computeCommand(ArgResults argResults) {
final list = <String?>[];
for (var command = argResults.command;
command != null;
command = command.command) {
for (
var command = argResults.command;
command != null;
command = command.command
) {
var commandName = command.name;

if (list.isEmpty) {
Expand Down Expand Up @@ -356,7 +360,8 @@ abstract class PubTopLevel {
static void addColorFlag(ArgParser argParser) {
argParser.addFlag(
'color',
help: 'Use colors in terminal output.\n'
help:
'Use colors in terminal output.\n'
'Defaults to color when connected to a '
'terminal, and no-color otherwise.',
);
Expand Down
120 changes: 66 additions & 54 deletions lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ For example (follow the same format including spaces):
// To avoid breaking changes we keep supporting them, but hide them from
// --help to discourage further use. Combining these with new syntax will
// fail.
argParser.addOption(
'git-url',
help: 'Git URL of the package',
hide: true,
);
argParser.addOption('git-url', help: 'Git URL of the package', hide: true);
argParser.addOption(
'git-ref',
help: 'Git branch or commit to be retrieved',
Expand Down Expand Up @@ -218,8 +214,10 @@ Specify multiple sdk packages with descriptors.''');
);
} on GitException {
final name = updates.first.ref.name;
dataError('Unable to resolve package "$name" with the given '
'git parameters.');
dataError(
'Unable to resolve package "$name" with the given '
'git parameters.',
);
} on SolveFailure catch (e) {
dataError(e.message);
} on WrappedException catch (e) {
Expand All @@ -231,18 +229,21 @@ Specify multiple sdk packages with descriptors.''');
for (final update in updates) {
final ref = update.ref;
final name = ref.name;
final resultPackage = solveResult.packages
.firstWhere((packageId) => packageId.name == name);
final resultPackage = solveResult.packages.firstWhere(
(packageId) => packageId.name == name,
);

/// Assert that [resultPackage] is within the original user's
/// expectations.
final constraint = update.constraint;
if (constraint != null && !constraint.allows(resultPackage.version)) {
final dependencyOverrides = resolutionPubspec.dependencyOverrides;
if (dependencyOverrides.isNotEmpty) {
dataError('"$name" resolved to "${resultPackage.version}" which '
'does not satisfy constraint "$constraint". This could be '
'caused by "dependency_overrides".');
dataError(
'"$name" resolved to "${resultPackage.version}" which '
'does not satisfy constraint "$constraint". This could be '
'caused by "dependency_overrides".',
);
}
}
}
Expand Down Expand Up @@ -294,8 +295,10 @@ Specify multiple sdk packages with descriptors.''');
}

if (isOffline) {
log.warning('Warning: Packages added when offline may not resolve to '
'the latest compatible version available.');
log.warning(
'Warning: Packages added when offline may not resolve to '
'the latest compatible version available.',
);
}
}

Expand All @@ -311,17 +314,21 @@ Specify multiple sdk packages with descriptors.''');
final dependencyOverrides = [...original.dependencyOverrides.values];

final dependencyNames = dependencies.map((dependency) => dependency.name);
final devDependencyNames =
devDependencies.map((devDependency) => devDependency.name);
final range =
package.ref.withConstraint(package.constraint ?? VersionConstraint.any);
final devDependencyNames = devDependencies.map(
(devDependency) => devDependency.name,
);
final range = package.ref.withConstraint(
package.constraint ?? VersionConstraint.any,
);

if (package.isOverride) {
dependencyOverrides.add(range);
} else if (package.isDev) {
if (devDependencyNames.contains(name)) {
log.message('"$name" is already in "dev_dependencies". '
'Will try to update the constraint.');
log.message(
'"$name" is already in "dev_dependencies". '
'Will try to update the constraint.',
);
devDependencies.removeWhere((element) => element.name == name);
}

Expand All @@ -330,9 +337,11 @@ Specify multiple sdk packages with descriptors.''');
/// remove the package from dependencies, since it might cause the user's
/// code to break.
if (dependencyNames.contains(name)) {
dataError('"$name" is already in "dependencies". '
'Use "pub remove $name" to remove it before adding it '
'to "dev_dependencies"');
dataError(
'"$name" is already in "dependencies". '
'Use "pub remove $name" to remove it before adding it '
'to "dev_dependencies"',
);
}

devDependencies.add(range);
Expand All @@ -349,8 +358,10 @@ Specify multiple sdk packages with descriptors.''');
/// dependencies, we remove the package from dev_dependencies, since it is
/// now redundant.
if (devDependencyNames.contains(name)) {
log.message('"$name" was found in dev_dependencies. '
'Removing "$name" and adding it to dependencies instead.');
log.message(
'"$name" was found in dev_dependencies. '
'Removing "$name" and adding it to dependencies instead.',
);
devDependencies.removeWhere((element) => element.name == name);
}

Expand Down Expand Up @@ -394,9 +405,10 @@ Specify multiple sdk packages with descriptors.''');
'The only allowed prefixes are "dev:" and "override:"',
);
} else {
final packageName = match2.namedGroup('descriptor') == null
? match2.namedGroup('prefix')
: match2.namedGroup('name');
final packageName =
match2.namedGroup('descriptor') == null
? match2.namedGroup('prefix')
: match2.namedGroup('name');
usageException('Not a valid package name: "$packageName"');
}
}
Expand Down Expand Up @@ -481,16 +493,18 @@ Specify multiple sdk packages with descriptors.''');
['sdk'],
];

for (final flag
in conflictingFlagSets.expand((s) => s).where(argResults.wasParsed)) {
for (final flag in conflictingFlagSets
.expand((s) => s)
.where(argResults.wasParsed)) {
final conflictingFlag = conflictingFlagSets
.where((s) => !s.contains(flag))
.expand((s) => s)
.firstWhereOrNull(argResults.wasParsed);
if (conflictingFlag != null) {
usageException(
'Packages can only have one source, "pub add" flags "--$flag" and '
'"--$conflictingFlag" are conflicting.');
'Packages can only have one source, "pub add" flags "--$flag" and '
'"--$conflictingFlag" are conflicting.',
);
}
}

Expand Down Expand Up @@ -632,12 +646,8 @@ Specify multiple sdk packages with descriptors.''');
try {
dummyPubspec = Pubspec.fromMap(
{
'dependencies': {
packageName: parsedDescriptor,
},
'environment': {
'sdk': sdk.version.toString(),
},
'dependencies': {packageName: parsedDescriptor},
'environment': {'sdk': sdk.version.toString()},
},
cache.sources,
// Resolve relative paths relative to current, not where the
Expand All @@ -654,7 +664,8 @@ Specify multiple sdk packages with descriptors.''');
} else {
ref = range.toRef();
}
final hasExplicitConstraint = parsedDescriptor is String ||
final hasExplicitConstraint =
parsedDescriptor is String ||
(parsedDescriptor is Map &&
parsedDescriptor.containsKey('version'));
// If the descriptor has an explicit constraint, use that. Otherwise we
Expand Down Expand Up @@ -682,15 +693,17 @@ Specify multiple sdk packages with descriptors.''');
List<PackageId> resultPackages,
List<_ParseResult> updates,
) {
final yamlEditor =
YamlEditor(readTextFile(entrypoint.workPackage.pubspecPath));
final yamlEditor = YamlEditor(
readTextFile(entrypoint.workPackage.pubspecPath),
);
log.io('Reading ${entrypoint.workPackage.pubspecPath}.');
log.fine('Contents:\n$yamlEditor');

for (final update in updates) {
final dependencyKey = update.isDev
? 'dev_dependencies'
: (update.isOverride ? 'dependency_overrides' : 'dependencies');
final dependencyKey =
update.isDev
? 'dev_dependencies'
: (update.isOverride ? 'dependency_overrides' : 'dependencies');
final constraint = update.constraint;
final ref = update.ref;
final name = ref.name;
Expand All @@ -707,19 +720,17 @@ Specify multiple sdk packages with descriptors.''');
entrypoint.workPackage,
);

if (yamlEditor.parseAt(
[dependencyKey],
orElse: () => YamlScalar.wrap(null),
).value ==
if (yamlEditor.parseAt([
dependencyKey,
], orElse: () => YamlScalar.wrap(null)).value ==
null) {
// Handle the case where [dependencyKey] does not already exist.
// We ensure it is in Block-style by default.
yamlEditor.update(
[dependencyKey],
wrapAsYamlNode(
{name: description},
collectionStyle: CollectionStyle.BLOCK,
),
wrapAsYamlNode({
name: description,
}, collectionStyle: CollectionStyle.BLOCK),
);
} else {
final packagePath = [dependencyKey, name];
Expand All @@ -731,8 +742,9 @@ Specify multiple sdk packages with descriptors.''');
/// dependencies. Refer to [_addPackageToPubspec] for additional
/// discussion.
if (!update.isDev && !update.isOverride) {
final devDependenciesNode = yamlEditor
.parseAt(['dev_dependencies'], orElse: () => YamlScalar.wrap(null));
final devDependenciesNode = yamlEditor.parseAt([
'dev_dependencies',
], orElse: () => YamlScalar.wrap(null));

if (devDependenciesNode is YamlMap &&
devDependenciesNode.containsKey(name)) {
Expand Down
Loading

0 comments on commit 639536a

Please sign in to comment.