mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
add trailing comma fix for literals
This PR extends the`add_trailing_comma` fix to handle for the [upcoming support of list/set/map literals in `require_trailing_commas`](https://github.com/dart-lang/linter/pull/3340). It's likely the tests in this PR will fail until sdk update the linter dependency to include https://github.com/dart-lang/linter/pull/3340 Closes https://github.com/dart-lang/sdk/pull/48968 GitOrigin-RevId: 24b374ec39b313640f7c06fbf8f725c09d3ed7ac Change-Id: I066a8524d18a4213eb5300b9310bdb4a562f0e27 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243920 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
bb3135586c
commit
04bcc30c58
|
@ -30,6 +30,10 @@ class AddTrailingComma extends CorrectionProducer {
|
|||
await _insertComma(builder, node.parameters.last);
|
||||
} else if (node is Assertion) {
|
||||
await _insertComma(builder, node.message ?? node.condition);
|
||||
} else if (node is ListLiteral) {
|
||||
await _insertComma(builder, node.elements.last);
|
||||
} else if (node is SetOrMapLiteral) {
|
||||
await _insertComma(builder, node.elements.last);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,50 @@ void f(a, b) {
|
|||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
Future<void> test_list_literal() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
var l = [
|
||||
'a',
|
||||
'b'
|
||||
];
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f() {
|
||||
var l = [
|
||||
'a',
|
||||
'b',
|
||||
];
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
Future<void> test_map_literal() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
var l = {
|
||||
'a': 1,
|
||||
'b': 2
|
||||
};
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f() {
|
||||
var l = {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
};
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_named() async {
|
||||
await resolveTestCode('''
|
||||
void f({a, b}) {
|
||||
|
@ -140,6 +184,28 @@ void f(a, b) {
|
|||
f('a',
|
||||
'b',);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
Future<void> test_set_literal() async {
|
||||
await resolveTestCode('''
|
||||
void f() {
|
||||
var l = {
|
||||
'a',
|
||||
'b'
|
||||
};
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f() {
|
||||
var l = {
|
||||
'a',
|
||||
'b',
|
||||
};
|
||||
print(l);
|
||||
}
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue