Skip to content

Commit fbe33e8

Browse files
committed
avoid_init_to_null bulk fix
Change-Id: I2c40b1028382d1818dc13a3f80e94184738016c1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156069 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 58a6e3c commit fbe33e8

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-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
@@ -11,6 +11,7 @@ import 'package:analysis_server/src/services/correction/dart/abstract_producer.d
1111
import 'package:analysis_server/src/services/correction/dart/add_override.dart';
1212
import 'package:analysis_server/src/services/correction/dart/convert_documentation_into_line.dart';
1313
import 'package:analysis_server/src/services/correction/dart/remove_const.dart';
14+
import 'package:analysis_server/src/services/correction/dart/remove_initializer.dart';
1415
import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_new.dart';
1516
import 'package:analysis_server/src/services/correction/dart/replace_cascade_with_dot.dart';
1617
import 'package:analysis_server/src/services/correction/dart/replace_colon_with_equals.dart';
@@ -29,6 +30,7 @@ class BulkFixProcessor {
2930
/// generators used for non-lint diagnostics are in the [nonLintProducerMap].
3031
static const Map<String, ProducerGenerator> lintProducerMap = {
3132
LintNames.annotate_overrides: AddOverride.newInstance,
33+
LintNames.avoid_init_to_null: RemoveInitializer.newInstance,
3234
LintNames.avoid_single_cascade_in_expression_statements:
3335
ReplaceCascadeWithDot.newInstance,
3436
LintNames.prefer_equal_for_default_values:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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(RemoveInitializerTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class RemoveInitializerTest extends BulkFixProcessorTest {
18+
@override
19+
String get lintCode => LintNames.avoid_init_to_null;
20+
21+
Future<void> test_singleFile() async {
22+
await resolveTestUnit('''
23+
class T {
24+
int x = null;
25+
}
26+
27+
class T2 {
28+
int x = null;
29+
}
30+
''');
31+
await assertHasFix('''
32+
class T {
33+
int x;
34+
}
35+
36+
class T2 {
37+
int x;
38+
}
39+
''');
40+
}
41+
}

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
@@ -7,6 +7,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
77
import 'add_override_test.dart' as add_override;
88
import 'convert_documentation_into_line_test.dart'
99
as convert_documentation_into_line;
10+
import 'remove_initializer_test.dart' as remove_initializer;
1011
import 'remove_unnecessary_const_test.dart' as remove_unnecessary_const;
1112
import 'remove_unnecessary_new_test.dart' as remove_unnecessary_new;
1213
import 'replace_colon_with_equals_test.dart' as replace_colon_with_equals;
@@ -15,6 +16,7 @@ void main() {
1516
defineReflectiveSuite(() {
1617
add_override.main();
1718
convert_documentation_into_line.main();
19+
remove_initializer.main();
1820
remove_unnecessary_const.main();
1921
remove_unnecessary_new.main();
2022
replace_colon_with_equals.main();

0 commit comments

Comments
 (0)