Fix prefer_iterable_wheretype in analyzer.
R=brianwilkerson@google.com
Change-Id: Id683ec62a7bdfddb5b2662afbcf57d884767a736
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127454
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/analysis_options.yaml b/pkg/analyzer/analysis_options.yaml
index a4d1e59..fe438af 100644
--- a/pkg/analyzer/analysis_options.yaml
+++ b/pkg/analyzer/analysis_options.yaml
@@ -10,7 +10,6 @@
# Ignoring "style" lint rules from pedantic for now. There are pre-existing
# violations that need to be cleaned up. Each one can be cleaned up and
# enabled according to the value provided.
- prefer_iterable_wheretype: ignore
# TODO(srawlins): At the time of writing, 2600 violations in lib/. The fix
# is mechanical, via `dartfmt --fix-doc-comments`, but not worth the churn
# today.
diff --git a/pkg/analyzer/lib/src/dart/resolver/scope.dart b/pkg/analyzer/lib/src/dart/resolver/scope.dart
index 7bdb63d..39785d9 100644
--- a/pkg/analyzer/lib/src/dart/resolver/scope.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/scope.dart
@@ -454,9 +454,10 @@
@override
bool shouldIgnoreUndefined(Identifier node) {
Iterable<NamespaceCombinator> getShowCombinators(
- ImportElement importElement) =>
- importElement.combinators.where((NamespaceCombinator combinator) =>
- combinator is ShowElementCombinator);
+ ImportElement importElement) {
+ return importElement.combinators.whereType<ShowElementCombinator>();
+ }
+
if (node is PrefixedIdentifier) {
String prefix = node.prefix.name;
String name = node.identifier.name;
diff --git a/pkg/analyzer/lib/src/workspace/gn.dart b/pkg/analyzer/lib/src/workspace/gn.dart
index 2c22481..b783f0b 100644
--- a/pkg/analyzer/lib/src/workspace/gn.dart
+++ b/pkg/analyzer/lib/src/workspace/gn.dart
@@ -252,8 +252,7 @@
}
return genDir
.getChildren()
- .where((resource) => resource is File)
- .map((resource) => resource as File)
+ .whereType<File>()
.where((File file) => pathContext.extension(file.path) == '.packages')
.map((File file) => file.path)
.toList();
@@ -285,11 +284,7 @@
if (!outDirectory.exists) {
return null;
}
- return outDirectory
- .getChildren()
- .where((resource) => resource is Folder)
- .map((resource) => resource as Folder)
- .firstWhere((Folder folder) {
+ return outDirectory.getChildren().whereType<Folder>().firstWhere((folder) {
String baseName = pathContext.basename(folder.path);
// Taking a best guess to identify a build dir. This is clearly a fallback
// to the config-based method.
diff --git a/pkg/analyzer/test/utils.dart b/pkg/analyzer/test/utils.dart
index bfb9fe1..c000337 100644
--- a/pkg/analyzer/test/utils.dart
+++ b/pkg/analyzer/test/utils.dart
@@ -16,8 +16,7 @@
*/
FunctionElement findLocalFunction(CompilationUnit unit, String name) {
List<Element> elements = findElementsByName(unit, name);
- List<Element> functions =
- elements.where((e) => e is FunctionElement).toList();
+ List<Element> functions = elements.whereType<FunctionElement>().toList();
expect(functions, hasLength(1));
return functions[0];
}
@@ -29,7 +28,7 @@
LocalVariableElement findLocalVariable(CompilationUnit unit, String name) {
List<Element> elements = findElementsByName(unit, name);
List<Element> localVariables =
- elements.where((e) => e is LocalVariableElement).toList();
+ elements.whereType<LocalVariableElement>().toList();
expect(localVariables, hasLength(1));
return localVariables[0];
}