linter icon indicating copy to clipboard operation
linter copied to clipboard

Potential false-negative for `prefer_null_aware_method_calls`

Open incendial opened this issue 2 years ago • 0 comments

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.

incendial avatar Oct 10 '23 14:10 incendial