Skip to content

Add unnecessary_lambdas lint #1978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dwds/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ linter:
- prefer_final_locals
- unawaited_futures
- avoid_void_async
- unnecessary_lambdas
4 changes: 1 addition & 3 deletions dwds/debug_extension_mv3/web/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ void _showSavedMsg() {
final snackbar = document.getElementById('savedSnackbar');
if (snackbar == null) return;
snackbar.classes.add('show');
Timer(Duration(seconds: 3), () {
_maybeHideSavedMsg();
});
Timer(Duration(seconds: 3), _maybeHideSavedMsg);
}

void _maybeHideSavedMsg() {
Expand Down
10 changes: 2 additions & 8 deletions dwds/debug_extension_mv3/web/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ Future<Tab> createTab(String url, {bool inNewWindow = false}) {
active: true,
url: url,
),
allowInterop(
(Tab tab) {
completer.complete(tab);
},
),
allowInterop(completer.complete),
);
}
return completer.future;
}

Future<Tab?> getTab(int tabId) {
final completer = Completer<Tab?>();
chrome.tabs.get(tabId, allowInterop((tab) {
completer.complete(tab);
}));
chrome.tabs.get(tabId, allowInterop(completer.complete));
return completer.future;
}

Expand Down
3 changes: 1 addition & 2 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ class Locations {
///
/// This will populate the [_sourceToLocation] and [_moduleToLocations] maps.
Future<Set<Location>> _locationsForModule(String module) async {
final memoizer =
_locationMemoizer.putIfAbsent(module, () => AsyncMemoizer());
final memoizer = _locationMemoizer.putIfAbsent(module, AsyncMemoizer.new);

return await memoizer.runOnce(() async {
if (_moduleToLocations.containsKey(module)) {
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class DevHandler {
.takeUntilGap(const Duration(milliseconds: 50));
// We enqueue this work as we need to begin listening (`.hasNext`)
// before events are received.
safeUnawaited(Future.microtask(() => connection.runtime.enable()));
safeUnawaited(Future.microtask(connection.runtime.enable));

await for (var contextId in contextIds) {
final result = await connection.sendCommand('Runtime.evaluate', {
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ChromeProxyService implements VmServiceInterface {
_skipLists,
root,
);
debugger.then((value) => _debuggerCompleter.complete(value));
debugger.then(_debuggerCompleter.complete);
}

static Future<ChromeProxyService> create(
Expand Down
4 changes: 1 addition & 3 deletions dwds/test/extension_debugger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ void main() async {
..success = true);
final resultCompleter = Completer();
unawaited(extensionDebugger.sendCommand('Runtime.evaluate',
params: {'expression': '\$pi'}).then((response) {
resultCompleter.complete(response);
}));
params: {'expression': '\$pi'}).then(resultCompleter.complete));
connection.controllerIncoming.sink
.add(jsonEncode(serializers.serialize(extensionResponse)));
final response = await resultCompleter.future;
Expand Down
3 changes: 1 addition & 2 deletions dwds/test/fixtures/debugger_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
///
/// This is taken from a real run, but truncated to two levels of scope and one
/// level of stack.
List<WipCallFrame> frames1 =
frames1Json.map((json) => WipCallFrame(json)).toList();
List<WipCallFrame> frames1 = frames1Json.map(WipCallFrame.new).toList();

List<Map<String, dynamic>> frames1Json = [
{
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/instances/instance_inspection_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Matcher matchPrimitiveInstance(
{required String kind, required dynamic value}) =>
isA<Instance>()
.having((e) => e.kind, 'kind', kind)
.having((e) => _getValue(e), 'value', value);
.having(_getValue, 'value', value);

Matcher matchPlainInstance({required String type}) => isA<Instance>()
.having((e) => e.kind, 'kind', InstanceKind.kPlainInstance)
Expand Down
7 changes: 3 additions & 4 deletions dwds/test/sdk_configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ void main() {

test('Cannot validate an empty configuration layout', () async {
final emptyConfiguration = SdkConfiguration.empty();
expect(() => emptyConfiguration.validateSdkDir(),
_throwsDoesNotExistException);
expect(() => emptyConfiguration.validate(), _throwsDoesNotExistException);
expect(emptyConfiguration.validateSdkDir, _throwsDoesNotExistException);
expect(emptyConfiguration.validate, _throwsDoesNotExistException);
});
});

Expand Down Expand Up @@ -85,7 +84,7 @@ void main() {
final sdkConfiguration = TestSdkLayout.createConfiguration(sdkLayout);

sdkConfiguration.validateSdkDir();
expect(() => sdkConfiguration.validate(), _throwsDoesNotExistException);
expect(sdkConfiguration.validate, _throwsDoesNotExistException);
});
});

Expand Down
3 changes: 2 additions & 1 deletion dwds/web/promise.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Future<T> toFuture<T>(Promise<T> promise) {
final completer = Completer<T>();
promise.then(
allowInterop(completer.complete),
allowInterop((e) => completer.completeError(e)),
// TODO(annagrin): propagate stack trace from promise instead.
allowInterop((e) => completer.completeError(e, StackTrace.current)),
);
return completer.future;
}
4 changes: 1 addition & 3 deletions dwds/web/reloader/require_restarter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ class RequireRestarter implements Restarter {
final stackTrace = StackTrace.current;
requireLoader.forceLoadModule(
moduleId,
allowInterop(() {
completer.complete();
}),
allowInterop(completer.complete),
allowInterop((e) {
completer.completeError(
HotReloadFailedException(e.message), stackTrace);
Expand Down
2 changes: 1 addition & 1 deletion dwds/web/run_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:html';
/// More specifically, the script has the correct `nonce` value set.
final ScriptElement Function() _createScript = (() {
final nonce = _findNonce();
if (nonce == null) return () => ScriptElement();
if (nonce == null) return ScriptElement.new;

return () => ScriptElement()..setAttribute('nonce', nonce);
})();
Expand Down