File tree 7 files changed +141
-3
lines changed
test/src/services/correction/fix
7 files changed +141
-3
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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/correction/dart/abstract_producer.dart' ;
6
+ import 'package:analysis_server/src/services/correction/fix.dart' ;
7
+ import 'package:analyzer/dart/ast/ast.dart' ;
8
+ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
9
+ import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
10
+ import 'package:analyzer_plugin/utilities/range_factory.dart' ;
11
+
12
+ class RemoveBreak extends CorrectionProducer {
13
+ @override
14
+ bool get canBeAppliedInBulk => true ;
15
+
16
+ @override
17
+ bool get canBeAppliedToFile => true ;
18
+
19
+ @override
20
+ FixKind get fixKind => DartFixKind .REMOVE_BREAK ;
21
+
22
+ @override
23
+ FixKind get multiFixKind => DartFixKind .REMOVE_BREAK_MULTI ;
24
+
25
+ @override
26
+ Future <void > compute (ChangeBuilder builder) async {
27
+ final breakStatement = node;
28
+ if (breakStatement is BreakStatement ) {
29
+ await builder.addDartFileEdit (file, (builder) {
30
+ var start = utils.getLineContentStart (breakStatement.offset);
31
+ var end = utils.getLineContentEnd (breakStatement.end);
32
+ builder.addDeletion (range.startOffsetEndOffset (start, end));
33
+ });
34
+ }
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -2001,9 +2001,7 @@ LintCode.unnecessary_await_in_return:
2001
2001
LintCode.unnecessary_brace_in_string_interps :
2002
2002
status : hasFix
2003
2003
LintCode.unnecessary_breaks :
2004
- status : needsFix
2005
- notes : |-
2006
- https://github.com/dart-lang/sdk/issues/49960
2004
+ status : hasFix
2007
2005
LintCode.unnecessary_const :
2008
2006
status : hasFix
2009
2007
LintCode.unnecessary_constructor_name :
Original file line number Diff line number Diff line change @@ -944,6 +944,16 @@ class DartFixKind {
944
944
DartFixKindPriority .IN_FILE ,
945
945
'Remove awaits in file' ,
946
946
);
947
+ static const REMOVE_BREAK = FixKind (
948
+ 'dart.fix.remove.break' ,
949
+ DartFixKindPriority .DEFAULT ,
950
+ 'Remove break' ,
951
+ );
952
+ static const REMOVE_BREAK_MULTI = FixKind (
953
+ 'dart.fix.remove.break.multi' ,
954
+ DartFixKindPriority .IN_FILE ,
955
+ 'Remove unnecessary breaks in file' ,
956
+ );
947
957
static const REMOVE_CHARACTER = FixKind (
948
958
'dart.fix.remove.character' ,
949
959
DartFixKindPriority .DEFAULT ,
Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ import 'package:analysis_server/src/services/correction/dart/remove_argument.dar
118
118
import 'package:analysis_server/src/services/correction/dart/remove_assertion.dart' ;
119
119
import 'package:analysis_server/src/services/correction/dart/remove_assignment.dart' ;
120
120
import 'package:analysis_server/src/services/correction/dart/remove_await.dart' ;
121
+ import 'package:analysis_server/src/services/correction/dart/remove_break.dart' ;
121
122
import 'package:analysis_server/src/services/correction/dart/remove_character.dart' ;
122
123
import 'package:analysis_server/src/services/correction/dart/remove_comparison.dart' ;
123
124
import 'package:analysis_server/src/services/correction/dart/remove_const.dart' ;
@@ -662,6 +663,9 @@ class FixProcessor extends BaseProcessor {
662
663
LintNames .unnecessary_brace_in_string_interps: [
663
664
RemoveInterpolationBraces .new ,
664
665
],
666
+ LintNames .unnecessary_breaks: [
667
+ RemoveBreak .new ,
668
+ ],
665
669
LintNames .unnecessary_const: [
666
670
RemoveUnnecessaryConst .new ,
667
671
],
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ class LintNames {
140
140
static const String unawaited_futures = 'unawaited_futures' ;
141
141
static const String unnecessary_brace_in_string_interps =
142
142
'unnecessary_brace_in_string_interps' ;
143
+ static const String unnecessary_breaks = 'unnecessary_breaks' ;
143
144
static const String unnecessary_const = 'unnecessary_const' ;
144
145
static const String unnecessary_constructor_name =
145
146
'unnecessary_constructor_name' ;
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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/correction/fix.dart' ;
6
+ import 'package:analysis_server/src/services/linter/lint_names.dart' ;
7
+ import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
8
+ import 'package:test_reflective_loader/test_reflective_loader.dart' ;
9
+
10
+ import 'fix_processor.dart' ;
11
+
12
+ void main () {
13
+ defineReflectiveSuite (() {
14
+ defineReflectiveTests (RemoveBreakBulkTest );
15
+ defineReflectiveTests (RemoveBreakTest );
16
+ });
17
+ }
18
+
19
+ @reflectiveTest
20
+ class RemoveBreakBulkTest extends BulkFixProcessorTest {
21
+ @override
22
+ List <String > get experiments => ['patterns' , 'records' ];
23
+
24
+ @override
25
+ String get lintCode => LintNames .unnecessary_breaks;
26
+
27
+ Future <void > test_singleFile () async {
28
+ await resolveTestCode ('''
29
+ f() {
30
+ switch (1) {
31
+ case 1:
32
+ f();
33
+ break;
34
+ case 2:
35
+ f();
36
+ break;
37
+ }
38
+ }
39
+ ''' );
40
+ await assertHasFix ('''
41
+ f() {
42
+ switch (1) {
43
+ case 1:
44
+ f();
45
+ case 2:
46
+ f();
47
+ }
48
+ }
49
+ ''' );
50
+ }
51
+ }
52
+
53
+ @reflectiveTest
54
+ class RemoveBreakTest extends FixProcessorLintTest {
55
+ @override
56
+ List <String > get experiments => ['patterns' , 'records' ];
57
+
58
+ @override
59
+ FixKind get kind => DartFixKind .REMOVE_BREAK ;
60
+
61
+ @override
62
+ String get lintCode => LintNames .unnecessary_breaks;
63
+
64
+ Future <void > test_single () async {
65
+ await resolveTestCode ('''
66
+ f() {
67
+ switch (1) {
68
+ case 1:
69
+ f();
70
+ break;
71
+ case 2:
72
+ f();
73
+ }
74
+ }
75
+ ''' );
76
+ await assertHasFix ('''
77
+ f() {
78
+ switch (1) {
79
+ case 1:
80
+ f();
81
+ case 2:
82
+ f();
83
+ }
84
+ }
85
+ ''' );
86
+ }
87
+ }
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ import 'remove_argument_test.dart' as remove_argument;
147
147
import 'remove_assertion_test.dart' as remove_assertion;
148
148
import 'remove_assignment_test.dart' as remove_assignment;
149
149
import 'remove_await_test.dart' as remove_await;
150
+ import 'remove_break_test.dart' as remove_break;
150
151
import 'remove_character_test.dart' as remove_character;
151
152
import 'remove_comparison_test.dart' as remove_comparison;
152
153
import 'remove_const_test.dart' as remove_const;
@@ -381,6 +382,7 @@ void main() {
381
382
remove_assertion.main ();
382
383
remove_assignment.main ();
383
384
remove_await.main ();
385
+ remove_break.main ();
384
386
remove_character.main ();
385
387
remove_comparison.main ();
386
388
remove_const.main ();
You can’t perform that action at this time.
0 commit comments