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
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。