Open yelliver opened 2 years ago
The rule is not in place to encourage shorter code, but to encourage more performant code (I think) which doesn't involve unnecessary closures. In any case it's more idiomatic (https://dart.dev/guides/language/effective-dart/usage#avoid-using-iterableforeach-with-a-function-literal).
Of course there isn't documentation on the lint rule explaining this; I'll leave it open for now to support adding such documentation.
(We could also lobby for the formatter/style guide to accept for (var person in people) person.foo(param);
on one line, like we do for single-line if
s.)
Describe the issue This rule https://dart-lang.github.io/linter/lints/avoid_function_literals_in_foreach_calls.html
To Reproduce Having this line of code (and got the waring violating the rule):
people.forEach((person) => person.foo(param));
Expected behavior I think the above code still satisfies the principle of the rule because when using expression body, it is just 1 line