This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
lib/src/services/correction
test/src/services/correction/fix/bulk Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import 'package:analysis_server/src/services/correction/dart/convert_quotes.dart
1717import 'package:analysis_server/src/services/correction/dart/convert_to_contains.dart' ;
1818import 'package:analysis_server/src/services/correction/dart/convert_to_generic_function_syntax.dart' ;
1919import 'package:analysis_server/src/services/correction/dart/convert_to_if_null.dart' ;
20+ import 'package:analysis_server/src/services/correction/dart/convert_to_where_type.dart' ;
2021import 'package:analysis_server/src/services/correction/dart/create_method.dart' ;
2122import 'package:analysis_server/src/services/correction/dart/make_final.dart' ;
2223import 'package:analysis_server/src/services/correction/dart/remove_argument.dart' ;
@@ -91,6 +92,7 @@ class BulkFixProcessor {
9192 LintNames .prefer_if_null_operators: ConvertToIfNull .newInstance,
9293 LintNames .prefer_is_empty: ReplaceWithIsEmpty .newInstance,
9394 LintNames .prefer_is_not_empty: UesIsNotEmpty .newInstance,
95+ LintNames .prefer_iterable_whereType: ConvertToWhereType .newInstance,
9496 LintNames .prefer_single_quotes: ConvertToSingleQuotes .newInstance,
9597 LintNames .prefer_spread_collections: ConvertAddAllToSpread .newInstance,
9698 LintNames .slash_for_doc_comments: ConvertDocumentationIntoLine .newInstance,
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'package:analysis_server/src/services/linter/lint_names.dart' ;
6+ import 'package:test_reflective_loader/test_reflective_loader.dart' ;
7+
8+ import 'bulk_fix_processor.dart' ;
9+
10+ void main () {
11+ defineReflectiveSuite (() {
12+ defineReflectiveTests (ConvertToWhereTypeTest );
13+ });
14+ }
15+
16+ @reflectiveTest
17+ class ConvertToWhereTypeTest extends BulkFixProcessorTest {
18+ @override
19+ String get lintCode => LintNames .prefer_iterable_whereType;
20+
21+ Future <void > test_singleFile () async {
22+ await resolveTestUnit ('''
23+ Iterable<C> f(List<Object> list) {
24+ return list.where((e) => e is C);
25+ }
26+ Iterable<C> f2(List<Object> list) =>
27+ list.where((e) => e is C);
28+
29+ class C {}
30+ ''' );
31+ await assertHasFix ('''
32+ Iterable<C> f(List<Object> list) {
33+ return list.whereType<C>();
34+ }
35+ Iterable<C> f2(List<Object> list) =>
36+ list.whereType<C>();
37+
38+ class C {}
39+ ''' );
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import 'convert_to_if_null_test.dart' as convert_to_if_null;
1616import 'convert_to_single_quoted_strings_test.dart'
1717 as convert_to_single_quoted_strings;
1818import 'convert_to_spread_test.dart' as convert_to_spread;
19+ import 'convert_to_where_type_test.dart' as convert_to_where_type;
1920import 'create_method_test.dart' as create_method;
2021import 'make_final_test.dart' as make_final;
2122import 'remove_argument_test.dart' as remove_argument;
@@ -55,6 +56,7 @@ void main() {
5556 convert_to_if_null.main ();
5657 convert_to_single_quoted_strings.main ();
5758 convert_to_spread.main ();
59+ convert_to_where_type.main ();
5860 create_method.main ();
5961 make_final.main ();
6062 remove_argument.main ();
You can’t perform that action at this time.
0 commit comments