unnecessary_statements
Avoid using unnecessary statements.
This rule is available as of Dart 2.0.
Details
#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;
Usage
#To enable the unnecessary_statements
rule,
add unnecessary_statements
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- unnecessary_statements
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。