dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
630 stars 171 forks source link

unnecessary_lambdas should not trigger on extension type external methods #5015

Open a14n opened 1 month ago

a14n commented 1 month ago

With the following code:

extension type MapType._(JSObject _) implements JSObject {
  @JS('f')
  external void _f();
  void Function() get f => () => _f();
}

a lint unnecessary_lambdas appears on f getter.

But if I use a tear-off:

extension type MapType._(JSObject _) implements JSObject {
  @JS('f')
  external void _f();
  void Function() get f => _f;
}

then I get an error:

Error: Tear-offs of external extension type interop member '_f' are disallowed.

So unnecessary_lambdas should not trigger on extension type external methods

(Dart 3.4.4)

lrhn commented 1 month ago

Or maybe interop should support tear-of by generating a () => this._f() Dart function that you can tear of instead of the native function, if native functions can't be torn off directly.