目錄
目錄

Use trailing commas for all function calls and declarations.

This rule is available as of Dart 2.14.0.

This rule has a quick fix available.

Details

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 rule, add require_trailing_commas under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - require_trailing_commas