unnecessary_statements
Avoid using unnecessary statements.
此规则自 Dart 2.0 版本起可用。
详情
#AVOID using unnecessary statements.
Statements which have no clear effect are usually unnecessary, or should be broken up.
For example,
BAD:
dart
myvar;
list.clear;
1 + 2;
methodOne() + methodTwo();
foo ? bar : baz;
Though the added methods have a clear effect, the addition itself does not unless there is some magical overload of the + operator.
Usually code like this indicates an incomplete thought, and is a bug.
GOOD:
dart
some.method();
const SomeClass();
methodOne();
methodTwo();
foo ? bar() : baz();
return myvar;
使用方法
#要启用 unnecessary_statements
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 unnecessary_statements
:
analysis_options.yaml
yaml
linter:
rules:
- unnecessary_statements
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.