Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not add trailing commit the last positional parameter already… #57069

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer {
if (leftDelimiter == null) {
// There are no named parameters, so add the delimiters.
await builder.addDartFileEdit(file, (builder) {
builder.addInsertion(parameters.last.end, (builder) {
builder.write(', {');
var offset = parameters.last.hasCommaAfter ? 1 : 0;
var delimiter = parameters.last.hasCommaAfter ? '' : ',';
builder.addInsertion(parameters.last.end + offset, (builder) {
builder.write('$delimiter {');
writeKey(builder);
builder.write('}');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
AddKeyToConstructorsWithoutNamedArgumentsAnywhereTest,
);
defineReflectiveTests(AddKeyToConstructorsWithoutSuperParametersTest);
defineReflectiveTests(AddKeyToConstructorsWithPositionalParameterTest);
});
}

Expand Down Expand Up @@ -589,6 +590,50 @@ class B extends A {
}
}

@reflectiveTest
class AddKeyToConstructorsWithPositionalParameterTest
extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.ADD_KEY_TO_CONSTRUCTORS;

@override
String get lintCode => LintNames.use_key_in_widget_constructors;

@override
String get testPackageLanguageVersion => '2.16';

@override
void setUp() {
super.setUp();
writeTestPackageConfig(flutter: true);
}

Future<void> test_constructor_withPositional_noSuper() async {
await resolveTestCode('''
import 'package:flutter/material.dart';

class A extends StatelessWidget {
const A(
this.widget,
);

final Widget widget;
}
''');
await assertHasFix('''
import 'package:flutter/material.dart';

class A extends StatelessWidget {
const A(
this.widget, {super.key}
);

final Widget widget;
}
''');
}
}

@reflectiveTest
class AddKeyToConstructorsWithoutSuperParametersTest
extends FixProcessorLintTest {
Expand Down