require_trailing_commas
Use trailing commas for all parameter lists and argument lists.
This rule is available as of Dart 2.14.
This rule has a quick fix available.
Details
#DO use trailing commas for all multi-line parameter lists and argument lists. A parameter list or argument list that fits on one line, including the opening parenthesis and closing parenthesis, does not require a trailing comma.
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 argument in an argument list is positional (vs named) and is either a function literal with curly braces, a map literal, a set literal, or a list literal, then a trailing comma is not required. This exception only applies if the final argument does not fit entirely on one line.
NOTE: This lint rule assumes that code has been formatted with dart format
and may produce false positives on unformatted code.
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
Unless stated otherwise, the documentation on this site reflects Dart 3.5.3. Page last updated on 2024-07-03. View source or report an issue.