require_trailing_commas

Group: style

Maturity: stable

Dart SDK: >= 2.14.0 • (Linter v1.3.0)

Since info is static, may be stale
has-fix

View all Lint Rules

Using the Linter

DO use trailing commas for all function calls and declarations unless the function call or definition, from the start of the function name up to the closing parenthesis, fits in a single line.

BAD:

void run() {
  method('does not fit on one line',
      'test test test test test test test test test test test');
}

GOOD:

void run() {
  method(
    'does not fit on one line',
    'test test test test test test test test test test test',
  );
}

EXCEPTION: If the final parameter/argument is positional (vs named) and is either a function literal implemented using curly braces, a literal map, a literal set or a literal array. This exception only applies if the final parameter does not fit entirely on one line.

NOTE: This lint rule assumes dart format has been run over the code and may produce false positives until that has happened.

Usage

To enable the require_trailing_commas lint, add require_trailing_commas under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - require_trailing_commas