prefer-trailing-comma
Same as prefer-trailing-comma in Dart Code Metrics
- Group
- Style
- Path
lint/style/prefer-trailing-comma- Default
- Off, opt in
- Origin
- Dart Code Metrics
- Rule
- 411 of 512
Flags multi-line argument lists that are missing a trailing comma.
A trailing comma is required only when the argument list is already broken
across lines — when the last significant token sits on an earlier line than
the closing ). This mirrors the Dart 3.x tall-style formatter.
Invalid
// Bad: multi-line argument list without trailing comma
void example() {
functionCall(
'first',
'second',
'third'
);
final obj = MyClass(
fieldA,
fieldB,
fieldC
);
anotherFunc(
argOne,
argTwo,
argThree
);
}
void moreExamples() {
final nested = Container(
child: Column(
children: [1, 2, 3],
),
);
buildUI(
param1,
param2,
param3
);
}
void oneMore() {
final data = Provider(
child: Text(
'Hello World',
),
);
}
void needTrailingComma() {
configureApp(
debug: true,
verbose: false,
timeout: 30
);
} 'third' ); fieldC ); argThree ); param3 ); timeout: 30 );Valid
// Good: multi-line lists/calls with trailing commas
void example() {
functionCall(
'first',
'second',
'third',
);
}
class MyClass {
void methodCall(
String arg1,
int arg2,
bool arg3,
) {
print('$arg1 $arg2 $arg3');
}
}
final result = complex(
value1,
value2,
nested(
item1,
item2,
),
);
List<String> items = [
'a',
'b',
'c',
];
// OK: single-line calls don't need trailing commas
void single() {
print('hello');
functionCall('a', 'b', 'c');
}
// OK: single argument on multiple lines
void singleArg(
String veryLongArgumentName,
) {
print(veryLongArgumentName);
}
// OK: constructor with trailing comma
final obj = MyClass(
field1: 'value',
field2: 42,
);
// OK: map with trailing comma
final map = {
'key1': 'value1',
'key2': 'value2',
};
// OK: empty call is fine
void emptyCall() {
noArgs();
}Configure prefer-trailing-comma
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-trailing-comma": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-trailing-comma: <reason>More style rules
- prefer-transform-over-containerflutter
Prefers
Transformover aContainerused only fortransform. - prefer-type-over-var
Prefer explicit types over
varin ordinary variable declarations. - prefer-typing-uninitialized-variables
prefer_typing_uninitialized_variablesrecommendedFlags uninitialized variables declared without a type annotation.
- prefer-underscore-for-unused-callback-parameters
prefer_underscore_for_unused_callback_parametersFlags unused closure parameters that are not named with underscores.
- prefer-void-callbackflutter
Prefers Flutter's
VoidCallbackalias over a nongenericvoid Function()type. - provide-deprecation-message
provide_deprecation_messagerecommendedFlags
@deprecatedand@Deprecated()annotations that carry no message. - public-member-api-docs
public_member_api_docsDocuments public declarations and members in package libraries.
- record-fields-ordering
Flags named record type fields that violate the configured order.