Skip to content

Add unnecessary await in return lint #1981

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

Closed
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,4 +20,5 @@ linter:
- prefer_final_locals
- unawaited_futures
- avoid_void_async
- unnecessary_await_in_return
- unnecessary_lambdas
4 changes: 2 additions & 2 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Future<bool> _sendConnectFailureMessage(ConnectFailureReason reason,
final json = jsonEncode(serializers.serialize(ConnectFailure((b) => b
..tabId = dartAppTabId
..reason = reason.name)));
return await sendRuntimeMessage(
return sendRuntimeMessage(
type: MessageType.connectFailure,
body: json,
sender: Script.background,
Expand All @@ -490,7 +490,7 @@ Future<bool> _sendStopDebuggingMessage(DetachReason reason,
..tabId = dartAppTabId
..reason = reason.name
..newState = DebugStateChange.stopDebugging)));
return await sendRuntimeMessage(
return sendRuntimeMessage(
type: MessageType.debugStateChange,
body: json,
sender: Script.background,
Expand Down
6 changes: 3 additions & 3 deletions dwds/lib/src/debugging/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Debugger extends Domain {
final uri = oldRef?.uri;
if (uri == null) return null;
final dartUri = DartUri(uri, _root);
return await inspector.scriptRefFor(dartUri.serverPath);
return inspector.scriptRefFor(dartUri.serverPath);
}

Future<void> reestablishBreakpoints(
Expand Down Expand Up @@ -367,7 +367,7 @@ class Debugger extends Domain {
// TODO(alanknight): Can these be moved to dart_scope.dart?
final properties = await visibleProperties(debugger: this, frame: frame);
final boundVariables = await Future.wait(
properties.map((property) async => await _boundVariable(property)),
properties.map((property) async => _boundVariable(property)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
properties.map((property) async => _boundVariable(property)),
properties.map(_boundVariable)

I'd have to measure to be sure, but removing an async along with the await does have a chance at bringing perf improvements. In the cases where it was the only await in the method it could be worth removing along with the async - even if for only style reasons.

This case is nice because it can go further and become a tearoff. I'd make this change independent of the rest of the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do, thanks! I wasn't sure if there is any change in semantics:)

);

// Filter out variables that do not come from dart code, such as native
Expand Down Expand Up @@ -469,7 +469,7 @@ class Debugger extends Domain {
}
}
''';
return await inspector.jsCallFunctionOn(receiver, expression, args);
return inspector.jsCallFunctionOn(receiver, expression, args);
}

// TODO(elliette): https://github.com/dart-lang/webdev/issues/1501 Re-enable
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class AppInspector implements AppInspectorInterface {
// it's not really a Dart object.
if (isLibraryId(targetId)) {
final library = await getObject(targetId) as Library;
return await _invokeLibraryFunction(library, selector, remoteArguments);
return _invokeLibraryFunction(library, selector, remoteArguments);
} else {
return _invokeMethod(
remoteObjectFor(targetId), selector, remoteArguments);
Expand Down
12 changes: 6 additions & 6 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ class InstanceHelper extends Domain {
}

if (metaData.isSystemList) {
return await _listInstanceFor(classRef, remoteObject,
return _listInstanceFor(classRef, remoteObject,
offset: offset, count: count, length: metaData.length);
} else if (metaData.isSystemMap) {
return await _mapInstanceFor(classRef, remoteObject,
return _mapInstanceFor(classRef, remoteObject,
offset: offset, count: count, length: metaData.length);
} else if (metaData.isRecord) {
return await _recordInstanceFor(classRef, remoteObject,
return _recordInstanceFor(classRef, remoteObject,
offset: offset, count: count, length: metaData.length);
} else {
return await _plainInstanceFor(classRef, remoteObject,
return _plainInstanceFor(classRef, remoteObject,
offset: offset, count: count, length: metaData.length);
}
}
Expand Down Expand Up @@ -354,8 +354,8 @@ class InstanceHelper extends Domain {
count: count, elementCount: elements.length, length: length);
final range = elements.sublist(0, rangeCount);

return Future.wait(range
.map((element) async => await _instanceRefForRemote(element.value)));
return Future.wait(
range.map((element) async => _instanceRefForRemote(element.value)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
range.map((element) async => _instanceRefForRemote(element.value)));
range.map((element) => _instanceRefForRemote(element.value)));

Less interesting case since it doesn't become a tearoff, but if the sole await gets removed it is worth dropping the async too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nate, I will skip this PR for now and add the suggested change separately.

}

/// Return elements of the list from [properties].
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Locations {
Future<Set<Location>> _locationsForModule(String module) async {
final memoizer = _locationMemoizer.putIfAbsent(module, AsyncMemoizer.new);

return await memoizer.runOnce(() async {
return memoizer.runOnce(() async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only await, could drop the outer async.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do!

if (_moduleToLocations.containsKey(module)) {
return _moduleToLocations[module]!;
}
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/readers/proxy_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ProxyServerAssetReader implements AssetReader {
''');
return null;
} else {
return await response.readAsString();
return response.readAsString();
}
}

Expand Down
12 changes: 6 additions & 6 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
_checkIsolate('evaluate', isolateId);

final library = await inspector.getLibrary(targetId);
return await _getEvaluationResult(
return _getEvaluationResult(
isolateId,
() => evaluator.evaluateExpression(
isolateId, library?.uri, expression, scope),
Expand All @@ -522,7 +522,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
await isCompilerInitialized;
_checkIsolate('evaluateInFrame', isolateId);

return await _getEvaluationResult(
return _getEvaluationResult(
isolateId,
() => evaluator.evaluateExpressionInFrame(
isolateId, frameIndex, expression, scope),
Expand Down Expand Up @@ -588,7 +588,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(

@override
Future<ScriptList> getScripts(String isolateId) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could drop async

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do, thanks!

return await captureElapsedTime(() async {
return captureElapsedTime(() async {
await isInitialized;
_checkIsolate('getScripts', isolateId);
return inspector.getScripts();
Expand All @@ -606,10 +606,10 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
bool? reportLines,
List<String>? libraryFilters,
}) async {
return await captureElapsedTime(() async {
return captureElapsedTime(() async {
await isInitialized;
_checkIsolate('getSourceReport', isolateId);
return await inspector.getSourceReport(
return inspector.getSourceReport(
reports,
scriptId: scriptId,
tokenPos: tokenPos,
Expand Down Expand Up @@ -771,7 +771,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
await isInitialized;
await isStarted;
_checkIsolate('resume', isolateId);
return await (await debuggerFuture)
return (await debuggerFuture)
.resume(step: step, frameIndex: frameIndex);
}, (result) => DwdsEvent.resume(step));
} else {
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/puppeteer/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ Future<Page> _getPanelPage(
panelTarget ??=
await browser.waitForTarget((target) => target.url.contains(panelName));
panelTarget.type = 'page';
return await panelTarget.page;
return panelTarget.page;
}

Future<T> _evaluateInPanel<T>(
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/puppeteer/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Future<Browser> setUpExtensionTest(
isInternalBuild: isInternalBuild,
isFlutterApp: isFlutterApp,
);
return await puppeteer.launch(
return puppeteer.launch(
devTools: openChromeDevTools,
headless: false,
timeout: Duration(seconds: 60),
Expand Down
2 changes: 1 addition & 1 deletion dwds/web/reloader/require_restarter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class RequireRestarter implements Restarter {
// As function is async, it can potentially be called second time while
// first invocation is still running. In this case just mark as dirty and
// wait until loop from the first call will do the work
if (!_running.isCompleted) return await _running.future;
if (!_running.isCompleted) return _running.future;
_running = Completer();

var reloadedModules = 0;
Expand Down