From 9229b6db56c3d680fe982b63f082159d1b705a9f Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 8 Aug 2024 11:01:00 -0700 Subject: [PATCH] Replace some Map.containsKey with patterns (#490) In a few expressions where we check for the presence of a key, and then immediately read that key, refactor to an if-case which decomposes the variable inline. --- mono_repo/lib/src/package_config.dart | 7 ++----- mono_repo/lib/src/root_config.dart | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mono_repo/lib/src/package_config.dart b/mono_repo/lib/src/package_config.dart index e14ce8b4..d6d50c11 100644 --- a/mono_repo/lib/src/package_config.dart +++ b/mono_repo/lib/src/package_config.dart @@ -95,9 +95,7 @@ class PackageConfig { final stageYaml = stage.items; for (var job in stageYaml) { var jobSdks = rawConfig.sdks; - if (job is Map && job.containsKey('sdk')) { - final jobValue = job['sdk']; - + if (job case {'sdk': final jobValue}) { jobSdks = (jobValue is List) ? jobSdks = List.from(jobValue) : [jobValue as String]; @@ -149,8 +147,7 @@ class PackageConfig { } var jobOses = rawConfig.oses; - if (job is Map && job.containsKey('os')) { - final jobValue = job['os']; + if (job case {'os': final jobValue}) { if (jobValue is List) { jobOses = jobValue.cast(); } else { diff --git a/mono_repo/lib/src/root_config.dart b/mono_repo/lib/src/root_config.dart index e35d3629..6b0d2169 100644 --- a/mono_repo/lib/src/root_config.dart +++ b/mono_repo/lib/src/root_config.dart @@ -160,9 +160,8 @@ class RootConfig extends ListBase { } else if (yaml is Map) { const usesKey = 'uses'; - if (yaml.containsKey(usesKey)) { + if (yaml case {usesKey: final usage as String}) { // dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d - final usage = yaml[usesKey] as String; final match = usageRegex.firstMatch(usage); if (match != null) { result['${match.group(1)}/${match.group(2)}'] = match.group(3)!;