unnecessary_ statements
Avoid using unnecessary statements.
Details
#AVOID using unnecessary statements.
Statements which have no clear effect are usually unnecessary, or should be broken up.
For example,
BAD:
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:
some.method();
const SomeClass();
methodOne();
methodTwo();
foo ? bar() : baz();
return myvar;
Enable
#
To enable the
unnecessary_statements
rule, add
unnecessary_statements
under
linter > rules
in your
analysis_options.yaml
file:
linter:
rules:
- unnecessary_statements
If you're instead using the YAML map syntax to configure linter rules,
add
unnecessary_statements: true
under
linter > rules:
linter:
rules:
unnecessary_statements: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.