a16de199d7
This is a rediculously large CL, and if you want me to split it up I'm willing to do so. However, the changes were all made by running a script I wrote and then running the formatter over the code, so hopefully a spot-check will be sufficient. Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042 Reviewed-by: Samuel Rawlins <srawlins@google.com> SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
749 lines
12 KiB
Dart
749 lines
12 KiB
Dart
// 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:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import '../rule_test_support.dart';
|
|
|
|
void main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(RequireTrailingCommasTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class RequireTrailingCommasTest extends LintRuleTest {
|
|
@override
|
|
String get lintRule => LintNames.require_trailing_commas;
|
|
|
|
test_argumentList_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text',
|
|
'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsFunctionalBlockBody_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
() {
|
|
},
|
|
p3: 'Text',
|
|
);
|
|
}
|
|
void g(Object p1, Object p2, {Object? p3}) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsFunctionBlockBody() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(() {
|
|
}, 'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsFunctionBlockBody_endsWithNamed() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', () {
|
|
}, p3: 'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2, {Object? p3}) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsFunctionBlockBody_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
() {
|
|
},
|
|
'Text',
|
|
);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsListLiteral() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g([
|
|
'one',
|
|
'two',
|
|
], 'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsMapLiteral() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g({
|
|
'one': 'Text',
|
|
'two': 'Text',
|
|
}, 'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsMapLiteral_withTrailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
g('map literal', {
|
|
'one': 'Text',
|
|
'two': 'Text',
|
|
});
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_containsSetLiteral() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g({
|
|
'one',
|
|
'two',
|
|
}, 'Text'[!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithConstantListLiteral() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
const ['one', 'two'],
|
|
);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithFunctionBlockBody() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text',
|
|
() {}[!)!]; // LINT
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithFunctionBlockBody_multiLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('test', () {
|
|
});
|
|
}
|
|
void g(Object p1, Object p2, {Object? p3}) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithFunctionBlockBody_multiLine_named() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', 'Text', p3: () {
|
|
}[!)!];
|
|
}
|
|
void g(Object p1, Object p2, {Object? p3}) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithFunctionBlockBody_multiLine_named_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
'Text',
|
|
p3: () {
|
|
},
|
|
);
|
|
}
|
|
void g(Object p1, Object p2, {Object? p3}) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithFunctionBlockBody_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
() {},
|
|
);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithListLiteral() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', [
|
|
'one',
|
|
'two',
|
|
]);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithListLiteral_onSingleLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text',
|
|
const ['one', 'two'][!)!];
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithListLiteral_withTrailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', const [
|
|
'one',
|
|
'two',
|
|
]);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithMapLiteral() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text',
|
|
const {'one': '1', 'two': '2', 'three': '3'}[!)!]; // LINT
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithMapLiteral_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
const {'one': '1', 'two': '2', 'three': '3'},
|
|
);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithMapLiteral_withTrailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
g('Text', const {
|
|
'one': '1',
|
|
'two': '2',
|
|
});
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithSetLiteral() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
g('Text', {
|
|
'one',
|
|
'two',
|
|
});
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_endsWithSetLiteral_withTrailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', const {
|
|
'one',
|
|
'two',
|
|
});
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_multiLineString() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
print("""
|
|
Text
|
|
""");
|
|
}
|
|
''');
|
|
}
|
|
|
|
/// A representative test to ensure the lint is disabled when the language is 3.7 or higher.
|
|
test_argumentList_multiLine_post37() async {
|
|
await assertNoDiagnostics(r'''
|
|
void f() {
|
|
g('Text',
|
|
'Text');
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_multiLine_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g(
|
|
'Text',
|
|
'Text',
|
|
);
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_argumentList_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
g('Text', 'Text');
|
|
}
|
|
void g(Object p1, Object p2) {}
|
|
''');
|
|
}
|
|
|
|
test_assertStateent_multiLine_message_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(
|
|
false,
|
|
'Text',
|
|
);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_closure() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(() {
|
|
return true;
|
|
}());
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_closure_message() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(() {
|
|
return true;
|
|
}(), 'Text'[!)!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_closure_message_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(
|
|
() {
|
|
return true;
|
|
}(),
|
|
'Text',
|
|
);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_message() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(false, 'Text');
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_multiLine_message() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(false,
|
|
'Text'[!)!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_oneArgument_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert('Text'
|
|
.isNotEmpty[!)!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_assertStatement_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
assert(
|
|
'Text'.isNotEmpty,
|
|
);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_constructorAssertInitializer_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C()
|
|
: assert(true,
|
|
'Text'[!)!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_constructorAssertInitializer_multiLine_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C()
|
|
: assert(
|
|
true,
|
|
'Text',
|
|
);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_function_parameters_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void method4(int one,
|
|
int two[!)!] {}
|
|
''');
|
|
}
|
|
|
|
test_function_parameters_multiLine_withComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f(
|
|
int one,
|
|
int two,
|
|
) {}
|
|
''');
|
|
}
|
|
|
|
test_function_parameters_withNamed_mulitLine_withComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f(
|
|
int one, {
|
|
int? two,
|
|
}) {}
|
|
''');
|
|
}
|
|
|
|
test_function_parameters_withNamed_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f(int one,
|
|
{int two = 2[!}!]) {}
|
|
''');
|
|
}
|
|
|
|
test_function_parameters_withNamed_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void method1(Object p1, Object p2, {Object? param3, Object? param4}) {}
|
|
''');
|
|
}
|
|
|
|
test_functionLiteral_parameters_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
(int one,
|
|
int two[!)!]
|
|
{};
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_functionLiteral_parameters_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
(a, b) {};
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_listLiteral_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = [
|
|
1,
|
|
if (true) 2
|
|
[!]!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_listLiteral_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = [1, if (true) 2];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_mapLiteral_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = {
|
|
1: 1,
|
|
if (true) 2: 2
|
|
[!}!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_mapLiteral_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = {1: 1, if (true) 2: 2};
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_parameterList_multiLine_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C(
|
|
Object p1,
|
|
Object p2,
|
|
Object p3,
|
|
);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_parameterList_multiLineDefaultValue_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C(Object p1, Object p2,
|
|
[Object p3 = const [
|
|
'Text',
|
|
][!]!]);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_parameterList_multiLineDefaultValue_multiLine_trailingComma() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C(
|
|
Object p1,
|
|
Object p2, [
|
|
Object p3 = const [
|
|
'Text',
|
|
],
|
|
]);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_parameterList_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C(Object p1, Object p2);
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_parameterList_singleLine_blankLineBefore() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
class C {
|
|
C(
|
|
Object p1, Object p2, Object p3[!)!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_setLiteral_multiLine() async {
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = {
|
|
1,
|
|
if (true) 2
|
|
[!}!];
|
|
}
|
|
''');
|
|
}
|
|
|
|
test_setLiteral_singleLine() async {
|
|
await assertNoDiagnostics(r'''
|
|
// @dart = 3.6
|
|
// (pre tall-style)
|
|
|
|
void f() {
|
|
var x = {1, if (true) 2};
|
|
}
|
|
''');
|
|
}
|
|
}
|