Skip to content

Commit

Permalink
Replace some Map.containsKey with patterns (#490)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
natebosch authored Aug 8, 2024
1 parent ef70c95 commit 9229b6d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 2 additions & 5 deletions mono_repo/lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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<String>();
} else {
Expand Down
3 changes: 1 addition & 2 deletions mono_repo/lib/src/root_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ class RootConfig extends ListBase<PackageConfig> {
} 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)!;
Expand Down

0 comments on commit 9229b6d

Please sign in to comment.