Open jezell opened 1 month ago
@dcharkes Are these issues that the analyzer should be reporting? If so, should they be lints that are conditionally enabled or should they be warnings that are enabled by default?
As a side note, this was especially confusing because the compiler behavior changed in the current flutter beta. If a linter rule made it into the stable release, it would probably save a lot of people head scratching.
@bwilkerson I think you are meaning to ask @srujzs / @biggs0125. See also discussion on https://github.com/dart-lang/sdk/issues/54366
I think this can be added under the umbrella of https://github.com/dart-lang/sdk/issues/54366. I don't see a reason this should ever be a lint you can opt-out of as it's a compile-time error already. We may also find it easier to do some of the error reporting here with the analyzer so it's more obvious what's wrong with the user code.
anonymous_functions_tojs
Description
Warns about the usage of await and untyped arguments and how they interact with .toJS
Details
Anonymous functions can cause confusing compile time errors when passed to toJS. Avoid the use of await and specify types when passing anonymous functions directly to toJS. Future and dynamic are not allowed in functions passed to toJS but this doesn't show up until compile time.
Kind
Guards against compile errors
Bad Examples
These examples taken from dart-webrtc issue investigating changes in compiler behavior with flutter beta:
https://github.com/dart-lang/sdk/issues/56950
This fails to compile because
Future<None>
is not valid for toJSThis fails to compile because
dynamic event
is not valid for toJSGood Examples
Add a few examples that demonstrate a “good” adoption of this lint’s principle.
Discussion
At the moment the analyzer doesn't surface these compiler errors, but even if it did, the errors themselves can be confusing because dynamic and Future don't explicitly appear in these signatures.