Confusing messages with await_only_futures, unnecessary_parenthesis and futures with ternary operator

linter:
  rules:
    - await_only_futures
    - unnecessary_parenthesis
import 'dart:async';

main() async {
  bool cond = true;
  await (cond ? Future<void>.value(true) : Future<void>.value(true));
  await cond ? Future<void>.value(true) : Future<void>.value(true);
}

I’m sure one of those await lines should be valid, but the first one warns Unnecessary parenthesis can be removed. and the second one warns Await only futures.. I think one of them may be wrong?

Author: Fantashit

1 thought on “Confusing messages with await_only_futures, unnecessary_parenthesis and futures with ternary operator

  1. The one that is definitely wrong is the unnecessary parentheses warning.

    awaitExpression ::= await unaryExpression

    and conditionalExpression is not a unary expression.
    While you can remove the parentheses, it’s still syntactically valid, it won’t mean the same thing any more. It’ll be (await cond) ? ... or even awaiting some initial sub-expression of cond, if cond was a more complex expression. In that case you are awaiting a non-future, so that warning is correct.

    Ob-nitpick: It should probably say “Unnecessary parentheses can be removed” – removing just one isn’t going to work 🙂 Or “Unnecessary parenthesization”.

Comments are closed.