Change the ConvertToInitializingFormal availability to allow it in dart fix.

Change-Id: I9dc2a579f5c7a832bc3ba2adc4ea0ad965845397
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483361
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Robert Nystrom
2026-02-24 17:13:50 -08:00
committed by Commit Queue
parent d5e2f31993
commit 207e8f6f3c
4 changed files with 175 additions and 3 deletions
+52
View File
@@ -658,6 +658,58 @@ linter:
);
});
test('--apply (contiguous initializing formals require a second '
'pass)', () async {
// We can't convert contiguous leading initializers or assignments to
// initializing formals because the edits collide on the comma or
// whitespace between them. But two passes is enough to catch them all.
p = project(
mainSrc: '''
class C {
int a;
int b;
int c;
int d;
int e;
int f;
C(int a, int b, int c, int d, int e, int f) : a = a, b = b, c = c {
this.d = d;
this.e = e;
this.f = f;
}
}
''',
analysisOptions: '''
linter:
rules:
- prefer_initializing_formals
''',
);
var result = await p!.runFix(['--apply', '.'], workingDir: p!.dirPath);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(
result.stdout,
stringContainsInOrderWithVariableBullets([
'Applying fixes...',
'lib${Platform.pathSeparator}main.dart',
' prefer_initializing_formals $bullet 6',
'6 fixes made in 1 file.',
]),
);
expect(p!.findFile('lib/main.dart')!.readAsStringSync(), '''
class C {
int a;
int b;
int c;
int d;
int e;
int f;
C(this.a, this.b, this.c, this.d, this.e, this.f);
}
''');
});
group('AOT mode', () {
test('--use-aot-snapshot', () async {
p = project(