Skip to content

Commit

Permalink
Remove unnecessary imports of 'package:collection' IterableExtension (
Browse files Browse the repository at this point in the history
#4121)

* Replace `.whereNotNull()` with `.nonNulls` which is now in Dart core.
* `.firstOrNull`, `.lastOrNull`, `.singleOrNull` and `.elementAtOrNull(i)` are also in Dart core and even under the same name, so simply drop the import of 'package:collection' whenever possible.
  • Loading branch information
oprypin authored Jan 25, 2024
1 parent 7ce2474 commit 6bcd7e8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/src/command/upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:async';
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml_edit/yaml_edit.dart';
Expand Down Expand Up @@ -203,7 +202,7 @@ Consider using the Dart 2.19 sdk to migrate to null safety.''');
: [
for (final name in _packagesToUpgrade)
pubspec.dependencies[name] ?? pubspec.devDependencies[name],
].whereNotNull();
].nonNulls;
for (final range in toTighten) {
final constraint = (result[range] ?? range).constraint;
final resolvedVersion =
Expand Down
4 changes: 2 additions & 2 deletions lib/src/solver/failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _Writer {
// installed, if an SDK is incompatible with a dependency.
final notices = _root.externalIncompatibilities
.map((c) => c.cause.notice)
.whereNotNull()
.nonNulls
.toSet() // Avoid duplicates
.sortedBy((n) => n); // sort for consistency
for (final n in notices) {
Expand Down Expand Up @@ -156,7 +156,7 @@ class _Writer {
// understand how to fix the issue.
_root.externalIncompatibilities
.map((c) => c.cause.hint)
.whereNotNull()
.nonNulls
.toSet() // avoid duplicates
.sortedBy((hint) => hint) // sort hints for consistent ordering.
.forEach((hint) {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/source/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:async';
import 'dart:io';

import 'package:collection/collection.dart' show IterableNullableExtension;
import 'package:path/path.dart' as p;
import 'package:pool/pool.dart';
import 'package:pub_semver/pub_semver.dart';
Expand Down Expand Up @@ -444,7 +443,7 @@ class GitSource extends CachedSource {
}
});
})
.whereNotNull()
.nonNulls
.toList();

// Note that there may be multiple packages with the same name and version
Expand Down
5 changes: 2 additions & 3 deletions lib/src/source/hosted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import 'dart:io' as io;
import 'dart:io';
import 'dart:typed_data';

import 'package:collection/collection.dart'
show IterableExtension, IterableNullableExtension, maxBy;
import 'package:collection/collection.dart' show IterableExtension, maxBy;
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -1349,7 +1348,7 @@ class HostedSource extends CachedSource {
return null;
}
})
.whereNotNull()
.nonNulls
.toList();
}

Expand Down
3 changes: 1 addition & 2 deletions lib/src/system_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:io';

import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';

Expand Down Expand Up @@ -206,7 +205,7 @@ Consider setting the `PUB_CACHE` variable manually.
return null;
}),
))
.whereNotNull()
.nonNulls
.toList();

return versions;
Expand Down

0 comments on commit 6bcd7e8

Please sign in to comment.