dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.3k stars 1.59k forks source link

Warn if certain APIs are being used in a way that produce different results on VM and Web builds #58320

Open rydmike opened 3 years ago

rydmike commented 3 years ago

Linter rationale and background

Flutter makes cross platform development between VM and Web mainstream. Developers are thus more likely to run across APIs that while they work and are available on both platforms, might in some use-cases produce different results due to underlying implementation differences.

A linter rule that can detect usage of such APIs and use cases, and warn about the risk or issue, can help to avoid such errors and time consuming debugging.

Flutter code that was originally written to only consider VM builds, might later when built for Web as well, inadvertently use such APIs in such ways without the original use case being aware of the limitations in the Web platform. Such errors can be difficult to debug and find in the built Flutter web application.

Rule scope

The rule scope is general purpose for cross platform builds, but certainly driven by Flutter making it mainstream.

Example

An example of a case that occurred due to API's underlying implementation details differences in VM and Web was posted in this issue: https://github.com/dart-lang/sdk/issues/44876

bwilkerson commented 3 years ago

@Hixie Are there APIs that would make sense for us to flag?

Hixie commented 3 years ago

The only cases I'm aware of are doubles vs ints, how deferred library loading works, the platform-specific libraries (dart:io, dart:html, dart:js, dart:cli, etc), and Flutter plugins.