[linter] proposal: omit_obvious_native_types_in_native_fields_and_functions
#59777
Labels
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
omit_obvious_native_types_in_native_fields_and_functions
Description
Omit the native type in the
@Native
annotation when it can be inferred from the annotated declaration.Details
The
@Native
annotation indart:ffi
is used to link native fields or functions to Dart code.With the changes introduced in https://dart-review.googlesource.com/c/sdk/+/400840, the native type for functions annotated with
@Native
can now be inferred directly from their Dart signatures. (This capability already existed for fields.) As a result, explicitly specifying the native type is unnecessary in some cases, which helps make the code cleaner and more concise.Adding a lint to promote omitting redundant native types supports Dart’s focus on clean and expressive syntax. By leveraging type inference, developers can reduce boilerplate and make FFI bindings easier to maintain and understand.
Kind
Style.
Bad Examples
Good Examples
Considerations
@Native
annotations./cc @bwilkerson
/cc @dcharkes
The text was updated successfully, but these errors were encountered: