Skip to content

Commit 4b21941

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
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>
1 parent 7bf088e commit 4b21941

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

pkg/analyzer/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ analyzer:
1010
# Ignoring "style" lint rules from pedantic for now. There are pre-existing
1111
# violations that need to be cleaned up. Each one can be cleaned up and
1212
# enabled according to the value provided.
13-
prefer_iterable_wheretype: ignore
1413
# TODO(srawlins): At the time of writing, 2600 violations in lib/. The fix
1514
# is mechanical, via `dartfmt --fix-doc-comments`, but not worth the churn
1615
# today.

pkg/analyzer/lib/src/dart/resolver/scope.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ class LibraryImportScope extends Scope {
454454
@override
455455
bool shouldIgnoreUndefined(Identifier node) {
456456
Iterable<NamespaceCombinator> getShowCombinators(
457-
ImportElement importElement) =>
458-
importElement.combinators.where((NamespaceCombinator combinator) =>
459-
combinator is ShowElementCombinator);
457+
ImportElement importElement) {
458+
return importElement.combinators.whereType<ShowElementCombinator>();
459+
}
460+
460461
if (node is PrefixedIdentifier) {
461462
String prefix = node.prefix.name;
462463
String name = node.identifier.name;

pkg/analyzer/lib/src/workspace/gn.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ class GnWorkspace extends Workspace {
252252
}
253253
return genDir
254254
.getChildren()
255-
.where((resource) => resource is File)
256-
.map((resource) => resource as File)
255+
.whereType<File>()
257256
.where((File file) => pathContext.extension(file.path) == '.packages')
258257
.map((File file) => file.path)
259258
.toList();
@@ -285,11 +284,7 @@ class GnWorkspace extends Workspace {
285284
if (!outDirectory.exists) {
286285
return null;
287286
}
288-
return outDirectory
289-
.getChildren()
290-
.where((resource) => resource is Folder)
291-
.map((resource) => resource as Folder)
292-
.firstWhere((Folder folder) {
287+
return outDirectory.getChildren().whereType<Folder>().firstWhere((folder) {
293288
String baseName = pathContext.basename(folder.path);
294289
// Taking a best guess to identify a build dir. This is clearly a fallback
295290
// to the config-based method.

pkg/analyzer/test/utils.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import 'package:test/test.dart';
1616
*/
1717
FunctionElement findLocalFunction(CompilationUnit unit, String name) {
1818
List<Element> elements = findElementsByName(unit, name);
19-
List<Element> functions =
20-
elements.where((e) => e is FunctionElement).toList();
19+
List<Element> functions = elements.whereType<FunctionElement>().toList();
2120
expect(functions, hasLength(1));
2221
return functions[0];
2322
}
@@ -29,7 +28,7 @@ FunctionElement findLocalFunction(CompilationUnit unit, String name) {
2928
LocalVariableElement findLocalVariable(CompilationUnit unit, String name) {
3029
List<Element> elements = findElementsByName(unit, name);
3130
List<Element> localVariables =
32-
elements.where((e) => e is LocalVariableElement).toList();
31+
elements.whereType<LocalVariableElement>().toList();
3332
expect(localVariables, hasLength(1));
3433
return localVariables[0];
3534
}

0 commit comments

Comments
 (0)