Skip to content

Commit 2227249

Browse files
pqCommit Queue
authored andcommitted
[PE] [linter] don’t report require_trailing_commas if language >=3.7
Fixes: #60119 Change-Id: If4821300dcae05cd1283558a87481d2bad7dae9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411182 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 3a8ff10 commit 2227249

File tree

3 files changed

+317
-23
lines changed

3 files changed

+317
-23
lines changed

pkg/analysis_server/test/src/services/correction/fix/add_trailing_comma_test.dart

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ class AddTrailingCommaBulkTest extends BulkFixProcessorTest {
2626

2727
Future<void> test_bulk() async {
2828
await resolveTestCode('''
29+
// @dart = 3.6
30+
// (pre tall-style)
31+
2932
Object f(a, b) {
3033
f(f('a',
3134
'b'), 'b');
3235
return a;
3336
}
3437
''');
3538
await assertHasFix('''
39+
// @dart = 3.6
40+
// (pre tall-style)
41+
3642
Object f(a, b) {
3743
f(f('a',
3844
'b',), 'b',);
@@ -47,6 +53,9 @@ class AddTrailingCommaInFileTest extends FixInFileProcessorTest {
4753
Future<void> test_File() async {
4854
createAnalysisOptionsFile(lints: [LintNames.require_trailing_commas]);
4955
await resolveTestCode(r'''
56+
// @dart = 3.6
57+
// (pre tall-style)
58+
5059
Object f(a, b) {
5160
f(f('a',
5261
'b'), 'b');
@@ -56,6 +65,9 @@ Object f(a, b) {
5665
var fixes = await getFixesForFirstError();
5766
expect(fixes, hasLength(1));
5867
assertProduces(fixes.first, r'''
68+
// @dart = 3.6
69+
// (pre tall-style)
70+
5971
Object f(a, b) {
6072
f(f('a',
6173
'b',), 'b',);
@@ -73,31 +85,49 @@ class AddTrailingCommaRecordTest extends FixProcessorTest {
7385
Future<void> test_parse_literal_initialization() async {
7486
// ParserErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA
7587
await resolveTestCode('''
88+
// @dart = 3.6
89+
// (pre tall-style)
90+
7691
var r = const (1);
7792
''');
7893
await assertHasFix('''
94+
// @dart = 3.6
95+
// (pre tall-style)
96+
7997
var r = const (1,);
8098
''');
8199
}
82100

83101
Future<void> test_parse_type_initialization() async {
84102
// ParserErrorCode.RECORD_TYPE_ONE_POSITIONAL_NO_TRAILING_COMMA
85103
await resolveTestCode('''
104+
// @dart = 3.6
105+
// (pre tall-style)
106+
86107
(int) record = const (1,);
87108
''');
88109
await assertHasFix('''
110+
// @dart = 3.6
111+
// (pre tall-style)
112+
89113
(int,) record = const (1,);
90114
''');
91115
}
92116

93117
Future<void> test_warning_literal_assignment() async {
94118
// WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA
95119
await resolveTestCode('''
120+
// @dart = 3.6
121+
// (pre tall-style)
122+
96123
void f((int,) r) {
97124
r = (1);
98125
}
99126
''');
100127
await assertHasFix('''
128+
// @dart = 3.6
129+
// (pre tall-style)
130+
101131
void f((int,) r) {
102132
r = (1,);
103133
}
@@ -107,19 +137,31 @@ void f((int,) r) {
107137
Future<void> test_warning_literal_initialization() async {
108138
// WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA
109139
await resolveTestCode('''
140+
// @dart = 3.6
141+
// (pre tall-style)
142+
110143
(int,) r = (1);
111144
''');
112145
await assertHasFix('''
146+
// @dart = 3.6
147+
// (pre tall-style)
148+
113149
(int,) r = (1,);
114150
''');
115151
}
116152

117153
Future<void> test_warning_literal_return() async {
118154
// WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA
119155
await resolveTestCode('''
156+
// @dart = 3.6
157+
// (pre tall-style)
158+
120159
(int,) f() { return (1); }
121160
''');
122161
await assertHasFix('''
162+
// @dart = 3.6
163+
// (pre tall-style)
164+
123165
(int,) f() { return (1,); }
124166
''');
125167
}
@@ -135,12 +177,18 @@ class AddTrailingCommaTest extends FixProcessorLintTest {
135177

136178
Future<void> test_assert_initializer() async {
137179
await resolveTestCode('''
180+
// @dart = 3.6
181+
// (pre tall-style)
182+
138183
class C {
139184
C(a) : assert(a,
140185
'');
141186
}
142187
''');
143188
await assertHasFix('''
189+
// @dart = 3.6
190+
// (pre tall-style)
191+
144192
class C {
145193
C(a) : assert(a,
146194
'',);
@@ -150,12 +198,18 @@ class C {
150198

151199
Future<void> test_assert_statement() async {
152200
await resolveTestCode('''
201+
// @dart = 3.6
202+
// (pre tall-style)
203+
153204
void f(a, b) {
154205
assert(a ||
155206
b);
156207
}
157208
''');
158209
await assertHasFix('''
210+
// @dart = 3.6
211+
// (pre tall-style)
212+
159213
void f(a, b) {
160214
assert(a ||
161215
b,);
@@ -165,6 +219,9 @@ void f(a, b) {
165219

166220
Future<void> test_list_literal() async {
167221
await resolveTestCode('''
222+
// @dart = 3.6
223+
// (pre tall-style)
224+
168225
void f() {
169226
var l = [
170227
'a',
@@ -174,6 +231,9 @@ void f() {
174231
}
175232
''');
176233
await assertHasFix('''
234+
// @dart = 3.6
235+
// (pre tall-style)
236+
177237
void f() {
178238
var l = [
179239
'a',
@@ -186,18 +246,26 @@ void f() {
186246

187247
Future<void> test_list_literal_withNullAwareElement() async {
188248
await resolveTestCode('''
249+
// @dart = 3.6
250+
// (pre tall-style)
251+
189252
void f(String? s) {
190253
var l = [
191254
'a',
255+
// ignore: EXPERIMENT_NOT_ENABLED
192256
?s
193257
];
194258
print(l);
195259
}
196260
''');
197261
await assertHasFix('''
262+
// @dart = 3.6
263+
// (pre tall-style)
264+
198265
void f(String? s) {
199266
var l = [
200267
'a',
268+
// ignore: EXPERIMENT_NOT_ENABLED
201269
?s,
202270
];
203271
print(l);
@@ -207,6 +275,9 @@ void f(String? s) {
207275

208276
Future<void> test_map_literal() async {
209277
await resolveTestCode('''
278+
// @dart = 3.6
279+
// (pre tall-style)
280+
210281
void f() {
211282
var l = {
212283
'a': 1,
@@ -216,6 +287,9 @@ void f() {
216287
}
217288
''');
218289
await assertHasFix('''
290+
// @dart = 3.6
291+
// (pre tall-style)
292+
219293
void f() {
220294
var l = {
221295
'a': 1,
@@ -228,18 +302,26 @@ void f() {
228302

229303
Future<void> test_map_literal_withNullAwareKey() async {
230304
await resolveTestCode('''
305+
// @dart = 3.6
306+
// (pre tall-style)
307+
231308
void f(String? k) {
232309
var l = {
233310
'a': 1,
311+
// ignore: EXPERIMENT_NOT_ENABLED
234312
?k: 2
235313
};
236314
print(l);
237315
}
238316
''');
239317
await assertHasFix('''
318+
// @dart = 3.6
319+
// (pre tall-style)
320+
240321
void f(String? k) {
241322
var l = {
242323
'a': 1,
324+
// ignore: EXPERIMENT_NOT_ENABLED
243325
?k: 2,
244326
};
245327
print(l);
@@ -249,18 +331,26 @@ void f(String? k) {
249331

250332
Future<void> test_map_literal_withNullAwareValue() async {
251333
await resolveTestCode('''
334+
// @dart = 3.6
335+
// (pre tall-style)
336+
252337
void f(int? v) {
253338
var l = {
254339
'a': 1,
340+
// ignore: EXPERIMENT_NOT_ENABLED
255341
'b': ?v
256342
};
257343
print(l);
258344
}
259345
''');
260346
await assertHasFix('''
347+
// @dart = 3.6
348+
// (pre tall-style)
349+
261350
void f(int? v) {
262351
var l = {
263352
'a': 1,
353+
// ignore: EXPERIMENT_NOT_ENABLED
264354
'b': ?v,
265355
};
266356
print(l);
@@ -270,12 +360,18 @@ void f(int? v) {
270360

271361
Future<void> test_named() async {
272362
await resolveTestCode('''
363+
// @dart = 3.6
364+
// (pre tall-style)
365+
273366
void f({a, b}) {
274367
f(a: 'a',
275368
b: 'b');
276369
}
277370
''');
278371
await assertHasFix('''
372+
// @dart = 3.6
373+
// (pre tall-style)
374+
279375
void f({a, b}) {
280376
f(a: 'a',
281377
b: 'b',);
@@ -285,23 +381,35 @@ void f({a, b}) {
285381

286382
Future<void> test_parameters() async {
287383
await resolveTestCode('''
384+
// @dart = 3.6
385+
// (pre tall-style)
386+
288387
void f(a,
289388
b) {}
290389
''');
291390
await assertHasFix('''
391+
// @dart = 3.6
392+
// (pre tall-style)
393+
292394
void f(a,
293395
b,) {}
294396
''');
295397
}
296398

297399
Future<void> test_positional() async {
298400
await resolveTestCode('''
401+
// @dart = 3.6
402+
// (pre tall-style)
403+
299404
void f(a, b) {
300405
f('a',
301406
'b');
302407
}
303408
''');
304409
await assertHasFix('''
410+
// @dart = 3.6
411+
// (pre tall-style)
412+
305413
void f(a, b) {
306414
f('a',
307415
'b',);
@@ -311,6 +419,9 @@ void f(a, b) {
311419

312420
Future<void> test_set_literal() async {
313421
await resolveTestCode('''
422+
// @dart = 3.6
423+
// (pre tall-style)
424+
314425
void f() {
315426
var l = {
316427
'a',
@@ -320,6 +431,9 @@ void f() {
320431
}
321432
''');
322433
await assertHasFix('''
434+
// @dart = 3.6
435+
// (pre tall-style)
436+
323437
void f() {
324438
var l = {
325439
'a',
@@ -332,18 +446,26 @@ void f() {
332446

333447
Future<void> test_set_literal_withNullAwareElement() async {
334448
await resolveTestCode('''
449+
// @dart = 3.6
450+
// (pre tall-style)
451+
335452
void f(String? s) {
336453
var l = {
337454
'a',
455+
// ignore: EXPERIMENT_NOT_ENABLED
338456
?s
339457
};
340458
print(l);
341459
}
342460
''');
343461
await assertHasFix('''
462+
// @dart = 3.6
463+
// (pre tall-style)
464+
344465
void f(String? s) {
345466
var l = {
346467
'a',
468+
// ignore: EXPERIMENT_NOT_ENABLED
347469
?s,
348470
};
349471
print(l);

0 commit comments

Comments
 (0)