Rules / Style / prefer-trailing-comma

prefer-trailing-comma

lint/style/prefer-trailing-comma
recommended
Same as prefer-trailing-comma · Dart Code Metrics

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 — that is, when the last significant token sits on an earlier line than the closing ). This mirrors the Dart 3.x tall-style formatter, which adds a trailing comma when it splits a list one element per line and omits it when the final argument hugs the bracket, so the rule stays silent on single-line calls, trailing-closure arguments, and method chains. Adding the comma keeps diffs small and lets the formatter preserve the one-argument-per-line layout.

Invalid

example.dartdart
// 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
  );
}
Add a trailing comma to the argument list
6 'third'
7 );
Add a trailing comma to the argument list
12 fieldC
13 );
Add a trailing comma to the argument list
18 argThree
19 );
Add a trailing comma to the argument list
32 param3
33 );
Add a trailing comma to the argument list
48 timeout: 30
49 );

Valid

example.dartdart
// 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();
}

How to configure

Set the severity of prefer-trailing-comma in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-trailing-comma": "error"
      }
    }
  }
}