File tree 7 files changed +82
-21
lines changed
lib/src/services/correction
test/src/services/correction/fix 7 files changed +82
-21
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/source/source_range.dart' ;
9
+ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
10
+ import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
11
+
12
+ class RemoveVarKeyword extends ResolvedCorrectionProducer {
13
+ @override
14
+ FixKind get fixKind => DartFixKind .REMOVE_VAR_KEYWORD ;
15
+
16
+ @override
17
+ Future <void > compute (ChangeBuilder builder) async {
18
+ var node = coveredNode;
19
+ if (node is DeclaredVariablePattern ) {
20
+ var keyword = node.keyword;
21
+ if (keyword != null ) {
22
+ await builder.addDartFileEdit (file, (builder) {
23
+ builder.addDeletion (SourceRange (keyword.offset, keyword.length + 1 ));
24
+ });
25
+ }
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -3180,7 +3180,7 @@ ParserErrorCode.OUT_OF_ORDER_CLAUSES:
3180
3180
There isn't enough information for a fix. Consider splitting this diagnostic
3181
3181
so that each variant has enough information.
3182
3182
ParserErrorCode.PATTERN_ASSIGNMENT_DECLARES_VARIABLE :
3183
- status : noFix
3183
+ status : hasFix
3184
3184
ParserErrorCode.PATTERN_VARIABLE_DECLARATION_OUTSIDE_FUNCTION_OR_METHOD :
3185
3185
status : noFix
3186
3186
ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT :
Original file line number Diff line number Diff line change @@ -1513,6 +1513,11 @@ class DartFixKind {
1513
1513
DartFixKindPriority .DEFAULT ,
1514
1514
"Remove 'var'" ,
1515
1515
);
1516
+ static const REMOVE_VAR_KEYWORD = FixKind (
1517
+ 'dart.fix.remove.var.keyword' ,
1518
+ DartFixKindPriority .DEFAULT ,
1519
+ "Remove 'var'" ,
1520
+ );
1516
1521
static const RENAME_METHOD_PARAMETER = FixKind (
1517
1522
'dart.fix.rename.methodParameter' ,
1518
1523
DartFixKindPriority .DEFAULT ,
Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ import 'package:analysis_server/src/services/correction/dart/remove_unused_label
180
180
import 'package:analysis_server/src/services/correction/dart/remove_unused_local_variable.dart' ;
181
181
import 'package:analysis_server/src/services/correction/dart/remove_unused_parameter.dart' ;
182
182
import 'package:analysis_server/src/services/correction/dart/remove_var.dart' ;
183
+ import 'package:analysis_server/src/services/correction/dart/remove_var_keyword.dart' ;
183
184
import 'package:analysis_server/src/services/correction/dart/rename_method_parameter.dart' ;
184
185
import 'package:analysis_server/src/services/correction/dart/rename_to_camel_case.dart' ;
185
186
import 'package:analysis_server/src/services/correction/dart/replace_Null_with_void.dart' ;
@@ -1504,6 +1505,9 @@ class FixProcessor extends BaseProcessor {
1504
1505
ParserErrorCode .MIXIN_DECLARES_CONSTRUCTOR : [
1505
1506
RemoveConstructor .new ,
1506
1507
],
1508
+ ParserErrorCode .PATTERN_ASSIGNMENT_DECLARES_VARIABLE : [
1509
+ RemoveVarKeyword .new ,
1510
+ ],
1507
1511
ParserErrorCode .RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA : [
1508
1512
AddTrailingComma .new ,
1509
1513
],
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:analyzer_plugin/utilities/fixes/fixes.dart' ;
7
+ import 'package:test_reflective_loader/test_reflective_loader.dart' ;
8
+
9
+ import 'fix_processor.dart' ;
10
+
11
+ void main () {
12
+ defineReflectiveSuite (() {
13
+ defineReflectiveTests (RemoveVarKeywordTest );
14
+ });
15
+ }
16
+
17
+ @reflectiveTest
18
+ class RemoveVarKeywordTest extends FixProcessorTest {
19
+ @override
20
+ FixKind get kind => DartFixKind .REMOVE_VAR_KEYWORD ;
21
+
22
+ Future <void > test_declaredVariablePattern_patternAssignment () async {
23
+ await resolveTestCode ('''
24
+ f() {
25
+ var a = 1;
26
+ var b = 2;
27
+ //ignore: unused_local_variable
28
+ (var a, b) = (3, 4);
29
+ print((a, b));
30
+ }
31
+ ''' );
32
+ await assertHasFix ('''
33
+ f() {
34
+ var a = 1;
35
+ var b = 2;
36
+ //ignore: unused_local_variable
37
+ (a, b) = (3, 4);
38
+ print((a, b));
39
+ }
40
+ ''' );
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -33,26 +33,6 @@ void f(int x) {
33
33
''' );
34
34
}
35
35
36
- @FailingTest (
37
- issue: 'https://github.com/dart-lang/sdk/issues/49960' ,
38
- reason: 'Fix once error is reported' )
39
- Future <void > test_declaredVariablePattern_patternAssignment () async {
40
- await resolveTestCode ('''
41
- f() {
42
- var a = 1;
43
- var b = 2;
44
- (var a, int b) = (3, 4);
45
- }
46
- ''' );
47
- await assertHasFix ('''
48
- f() {
49
- var a = 1;
50
- var b = 2;
51
- (a, int b) = (3, 4);
52
- }
53
- ''' );
54
- }
55
-
56
36
Future <void > test_declaredVariablePattern_patternVariableDeclaration () async {
57
37
await resolveTestCode ('''
58
38
f() {
Original file line number Diff line number Diff line change @@ -221,6 +221,7 @@ import 'remove_unused_import_test.dart' as remove_unused_import;
221
221
import 'remove_unused_label_test.dart' as remove_unused_label;
222
222
import 'remove_unused_local_variable_test.dart' as remove_unused_local_variable;
223
223
import 'remove_unused_parameter_test.dart' as remove_unused_parameter;
224
+ import 'remove_var_keyword_test.dart' as remove_var_keyword;
224
225
import 'remove_var_test.dart' as remove_var;
225
226
import 'rename_method_parameter_test.dart' as rename_method_parameter;
226
227
import 'rename_to_camel_case_test.dart' as rename_to_camel_case;
@@ -468,6 +469,7 @@ void main() {
468
469
remove_unused_local_variable.main ();
469
470
remove_unused_parameter.main ();
470
471
remove_var.main ();
472
+ remove_var_keyword.main ();
471
473
rename_method_parameter.main ();
472
474
rename_to_camel_case.main ();
473
475
replace_boolean_with_bool.main ();
You can’t perform that action at this time.
0 commit comments