Skip to content

Commit 2b93765

Browse files
pqcommit-bot@chromium.org
authored andcommitted
bulk fix for prefer_null_aware_operators
Change-Id: I12b0f8bded48cf17550b6d7203e7b45576953574 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
1 parent ebc055b commit 2b93765

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:analysis_server/src/services/correction/dart/convert_to_contains
1919
import 'package:analysis_server/src/services/correction/dart/convert_to_generic_function_syntax.dart';
2020
import 'package:analysis_server/src/services/correction/dart/convert_to_if_null.dart';
2121
import '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';
2223
import 'package:analysis_server/src/services/correction/dart/convert_to_where_type.dart';
2324
import 'package:analysis_server/src/services/correction/dart/create_method.dart';
2425
import '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,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'convert_to_generic_function_syntax_test.dart'
1616
import 'convert_to_if_element_test.dart' as convert_to_if_element;
1717
import 'convert_to_if_null_test.dart' as convert_to_if_null;
1818
import 'convert_to_int_literal_test.dart' as convert_to_int_literal;
19+
import 'convert_to_null_aware_test.dart' as convert_to_null_aware;
1920
import 'convert_to_single_quoted_strings_test.dart'
2021
as convert_to_single_quoted_strings;
2122
import '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();

0 commit comments

Comments
 (0)