From 5b956bd8a0eb2012f55d3e98fc0d3d8cc08f4dca Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 3 Sep 2020 23:57:35 +0000 Subject: [PATCH] bulk fix for `prefer_const_declarations` Change-Id: I5ee65d901d8777df032f447b8a56bf1d654b98f1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161824 Reviewed-by: Brian Wilkerson Commit-Queue: Phil Quitslund --- .../correction/bulk_fix_processor.dart | 2 ++ .../bulk/replace_final_with_const_test.dart | 31 +++++++++++++++++++ .../correction/fix/bulk/test_all.dart | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 pkg/analysis_server/test/src/services/correction/fix/bulk/replace_final_with_const_test.dart diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart index 99689b01dd1..09dd6362b48 100644 --- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart +++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart @@ -40,6 +40,7 @@ import 'package:analysis_server/src/services/correction/dart/remove_unnecessary_ import 'package:analysis_server/src/services/correction/dart/rename_to_camel_case.dart'; import 'package:analysis_server/src/services/correction/dart/replace_cascade_with_dot.dart'; import 'package:analysis_server/src/services/correction/dart/replace_colon_with_equals.dart'; +import 'package:analysis_server/src/services/correction/dart/replace_final_with_const.dart'; import 'package:analysis_server/src/services/correction/dart/replace_null_with_closure.dart'; import 'package:analysis_server/src/services/correction/dart/replace_with_conditional_assignment.dart'; import 'package:analysis_server/src/services/correction/dart/replace_with_is_empty.dart'; @@ -87,6 +88,7 @@ class BulkFixProcessor { LintNames.prefer_adjacent_string_concatenation: RemoveOperator.newInstance, LintNames.prefer_conditional_assignment: ReplaceWithConditionalAssignment.newInstance, + LintNames.prefer_const_declarations: ReplaceFinalWithConst.newInstance, LintNames.prefer_contains: ConvertToContains.newInstance, LintNames.prefer_equal_for_default_values: ReplaceColonWithEquals.newInstance, diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/replace_final_with_const_test.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/replace_final_with_const_test.dart new file mode 100644 index 00000000000..1eefe842eff --- /dev/null +++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/replace_final_with_const_test.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:analysis_server/src/services/linter/lint_names.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import 'bulk_fix_processor.dart'; + +void main() { + defineReflectiveSuite(() { + defineReflectiveTests(ReplaceFinalWithConstTest); + }); +} + +@reflectiveTest +class ReplaceFinalWithConstTest extends BulkFixProcessorTest { + @override + String get lintCode => LintNames.prefer_const_declarations; + + Future test_singleFile() async { + await resolveTestUnit(''' +final int a = 1; +final b = 1; +'''); + await assertHasFix(''' +const int a = 1; +const b = 1; +'''); + } +} diff --git a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart index 328aba086b2..169e7b5945f 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/bulk/test_all.dart @@ -41,6 +41,7 @@ import 'remove_unnecessary_const_test.dart' as remove_unnecessary_const; import 'remove_unnecessary_new_test.dart' as remove_unnecessary_new; import 'rename_to_camel_case_test.dart' as rename_to_camel_case; import 'replace_colon_with_equals_test.dart' as replace_colon_with_equals; +import 'replace_final_with_const_test.dart' as replace_final_with_const; import 'replace_null_with_closure_test.dart' as replace_null_with_closure; import 'replace_with_conditional_assignment_test.dart' as replace_with_conditional_assignment; @@ -87,6 +88,7 @@ void main() { rename_to_camel_case.main(); replace_with_conditional_assignment.main(); replace_colon_with_equals.main(); + replace_final_with_const.main(); replace_null_with_closure.main(); replace_with_is_empty.main(); replace_with_tear_off.main();