linter
linter copied to clipboard
Potential false-negative for `prefer_null_aware_method_calls`
Describe the issue
Looks like prefer_null_aware_method_calls does not support FunctionExpressionInvocation without !.
For example,
String someFn() => 'some';
final map = {'key': someFn};
String? example() {
final fn = map['some-key'];
return fn != null ? fn() : null; // <- no lint
}
but the conditional can be replaced with:
fn?.call();
Additional context Considering the example on the website, I'm not sure that the rule is intended to support this case, but the name sets this expectation for me. Please let me know if there is another rule that can help with this case.