always_put_control_body_on_new_line
Separate the control structure expression from its statement.
此规则自 Dart 2.0 版本起可用。
此规则提供 快速修复 。
详情
#From the style guide for the flutter repo:
DO separate the control structure expression from its statement.
Don't put the statement part of an if
, for
, while
, do
on the same line as the expression, even if it is short. Doing so makes it unclear that there is relevant code there. This is especially important for early returns.
BAD:
if (notReady) return;
if (notReady)
return;
else print('ok')
while (condition) i += 1;
GOOD:
if (notReady)
return;
if (notReady)
return;
else
print('ok')
while (condition)
i += 1;
Note that this rule can conflict with the Dart formatter, and should not be enabled when the Dart formatter is used.
使用方法
#要启用 always_put_control_body_on_new_line
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 always_put_control_body_on_new_line
:
linter:
rules:
- always_put_control_body_on_new_line
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.