require_trailing_commas
Use trailing commas for all parameter lists and argument lists.
此规则自 Dart 2.14 版本起可用。
此规则提供 快速修复 。
详情
#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.
使用方法
#要启用 require_trailing_commas
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 require_trailing_commas
:
linter:
rules:
- require_trailing_commas
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.