File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
lib/src/services/correction
test/src/services/correction/fix/bulk Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import 'package:analysis_server/src/services/correction/dart/convert_to_contains
1919import 'package:analysis_server/src/services/correction/dart/convert_to_generic_function_syntax.dart' ;
2020import 'package:analysis_server/src/services/correction/dart/convert_to_if_null.dart' ;
2121import 'package:analysis_server/src/services/correction/dart/convert_to_int_literal.dart' ;
22+ import 'package:analysis_server/src/services/correction/dart/convert_to_null_aware.dart' ;
2223import 'package:analysis_server/src/services/correction/dart/convert_to_where_type.dart' ;
2324import 'package:analysis_server/src/services/correction/dart/create_method.dart' ;
2425import 'package:analysis_server/src/services/correction/dart/make_final.dart' ;
@@ -99,6 +100,7 @@ class BulkFixProcessor {
99100 LintNames .prefer_is_empty: ReplaceWithIsEmpty .newInstance,
100101 LintNames .prefer_is_not_empty: UesIsNotEmpty .newInstance,
101102 LintNames .prefer_iterable_whereType: ConvertToWhereType .newInstance,
103+ LintNames .prefer_null_aware_operators: ConvertToNullAware .newInstance,
102104 LintNames .prefer_single_quotes: ConvertToSingleQuotes .newInstance,
103105 LintNames .prefer_spread_collections: ConvertAddAllToSpread .newInstance,
104106 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 (ConvertToNullAwareTest );
13+ });
14+ }
15+
16+ @reflectiveTest
17+ class ConvertToNullAwareTest extends BulkFixProcessorTest {
18+ @override
19+ String get lintCode => LintNames .prefer_null_aware_operators;
20+
21+ Future <void > test_singleFile () async {
22+ await resolveTestUnit ('''
23+ abstract class A {
24+ int m();
25+ }
26+ int f(A a) => null == a ? null : a.m();
27+ int g(A a) => a == null ? null : a.m();
28+ ''' );
29+ await assertHasFix ('''
30+ abstract class A {
31+ int m();
32+ }
33+ int f(A a) => a?.m();
34+ int g(A a) => a?.m();
35+ ''' );
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import 'convert_to_generic_function_syntax_test.dart'
1616import 'convert_to_if_element_test.dart' as convert_to_if_element;
1717import 'convert_to_if_null_test.dart' as convert_to_if_null;
1818import 'convert_to_int_literal_test.dart' as convert_to_int_literal;
19+ import 'convert_to_null_aware_test.dart' as convert_to_null_aware;
1920import 'convert_to_single_quoted_strings_test.dart'
2021 as convert_to_single_quoted_strings;
2122import 'convert_to_spread_test.dart' as convert_to_spread;
@@ -60,6 +61,7 @@ void main() {
6061 convert_to_if_element.main ();
6162 convert_to_if_null.main ();
6263 convert_to_int_literal.main ();
64+ convert_to_null_aware.main ();
6365 convert_to_single_quoted_strings.main ();
6466 convert_to_spread.main ();
6567 convert_to_where_type.main ();
You can’t perform that action at this time.
0 commit comments