mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 15:39:54 +00:00
quick fix for COLON_IN_PLACE_OF_IN
See: https://github.com/dart-lang/sdk/issues/55917 Change-Id: I2dbe760dd0d123fc4b1bf493c8f7699baaea376c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370503 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
55a12750ec
commit
19c5914ce5
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2024, 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/correction/fix.dart';
|
||||
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
|
||||
class ReplaceColonWithIn extends ResolvedCorrectionProducer {
|
||||
ReplaceColonWithIn({required super.context});
|
||||
|
||||
@override
|
||||
CorrectionApplicability get applicability =>
|
||||
CorrectionApplicability.automatically;
|
||||
|
||||
@override
|
||||
FixKind get fixKind => DartFixKind.REPLACE_COLON_WITH_IN;
|
||||
|
||||
@override
|
||||
FixKind get multiFixKind => DartFixKind.REPLACE_COLON_WITH_IN_MULTI;
|
||||
|
||||
@override
|
||||
Future<void> compute(ChangeBuilder builder) async {
|
||||
var diagnostic = this.diagnostic;
|
||||
if (diagnostic == null) return;
|
||||
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(
|
||||
SourceRange(diagnostic.problemMessage.offset, 1), 'in');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -45,8 +45,8 @@
|
|||
#
|
||||
# Stats:
|
||||
# - 42 "needsEvaluation"
|
||||
# - 330 "needsFix"
|
||||
# - 418 "hasFix"
|
||||
# - 329 "needsFix"
|
||||
# - 419 "hasFix"
|
||||
# - 516 "noFix"
|
||||
|
||||
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
|
||||
|
@ -2568,9 +2568,7 @@ ParserErrorCode.CLASS_IN_CLASS:
|
|||
notes: |-
|
||||
Move the inner class to the top-level.
|
||||
ParserErrorCode.COLON_IN_PLACE_OF_IN:
|
||||
status: needsFix
|
||||
notes: |-
|
||||
Replace the `:` with `in`.
|
||||
status: hasFix
|
||||
ParserErrorCode.CONFLICTING_MODIFIERS:
|
||||
status: needsFix
|
||||
notes: |-
|
||||
|
|
|
@ -1582,6 +1582,16 @@ class DartFixKind {
|
|||
DartFixKindPriority.IN_FILE,
|
||||
"Replace ':'s with '='s everywhere in file",
|
||||
);
|
||||
static const REPLACE_COLON_WITH_IN = FixKind(
|
||||
'dart.fix.replace.colonWithIn',
|
||||
DartFixKindPriority.DEFAULT,
|
||||
"Replace ':' with 'in'",
|
||||
);
|
||||
static const REPLACE_COLON_WITH_IN_MULTI = FixKind(
|
||||
'dart.fix.replace.colonWithIn.multi',
|
||||
DartFixKindPriority.IN_FILE,
|
||||
"Replace ':'s with 'in's everywhere in file",
|
||||
);
|
||||
static const REPLACE_FINAL_WITH_CONST = FixKind(
|
||||
'dart.fix.replace.finalWithConst',
|
||||
DartFixKindPriority.DEFAULT,
|
||||
|
|
|
@ -188,6 +188,7 @@ import 'package:analysis_server/src/services/correction/dart/rename_to_camel_cas
|
|||
import 'package:analysis_server/src/services/correction/dart/replace_boolean_with_bool.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_colon_with_in.dart';
|
||||
import 'package:analysis_server/src/services/correction/dart/replace_container_with_sized_box.dart';
|
||||
import 'package:analysis_server/src/services/correction/dart/replace_empty_map_pattern.dart';
|
||||
import 'package:analysis_server/src/services/correction/dart/replace_final_with_const.dart';
|
||||
|
@ -1361,6 +1362,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
|
|||
ParserErrorCode.ABSTRACT_STATIC_METHOD: [
|
||||
RemoveLexeme.modifier,
|
||||
],
|
||||
ParserErrorCode.COLON_IN_PLACE_OF_IN: [
|
||||
ReplaceColonWithIn.new,
|
||||
],
|
||||
ParserErrorCode.CONST_CLASS: [
|
||||
RemoveConst.new,
|
||||
],
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2024, 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/correction/fix.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'fix_processor.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ReplaceColonWithInTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ReplaceColonWithInTest extends FixProcessorTest {
|
||||
@override
|
||||
FixKind get kind => DartFixKind.REPLACE_COLON_WITH_IN;
|
||||
|
||||
Future<void> test_colonInPlaceOfIn() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
for (var _ : []) {}
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f() {
|
||||
for (var _ in []) {}
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
|
@ -240,6 +240,7 @@ import 'rename_to_camel_case_test.dart' as rename_to_camel_case;
|
|||
import 'replace_boolean_with_bool_test.dart' as replace_boolean_with_bool;
|
||||
import 'replace_cascade_with_dot_test.dart' as replace_cascade_with_dot;
|
||||
import 'replace_colon_with_equals_test.dart' as replace_colon_with_equals;
|
||||
import 'replace_colon_with_in_test.dart' as replace_colon_with_in;
|
||||
import 'replace_container_with_sized_box_test.dart'
|
||||
as replace_container_with_sized_box;
|
||||
import 'replace_empty_amp_pattern_test.dart' as replace_empty_amp_pattern;
|
||||
|
@ -497,6 +498,7 @@ void main() {
|
|||
replace_boolean_with_bool.main();
|
||||
replace_cascade_with_dot.main();
|
||||
replace_colon_with_equals.main();
|
||||
replace_colon_with_in.main();
|
||||
replace_container_with_sized_box.main();
|
||||
replace_empty_amp_pattern.main();
|
||||
replace_final_with_const.main();
|
||||
|
|
Loading…
Reference in a new issue