Skip to content

Commit 20755e2

Browse files
srawlinsCommit Queue
authored andcommitted
linter: Add documentation to the 'unnecessary_unawaited' lint rule
Change-Id: I2e46a3bdbbe40ae3e0e383eb75357ea38ea95596 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428581 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent d5b82a3 commit 20755e2

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

pkg/linter/messages.yaml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13593,11 +13593,50 @@ LintCode:
1359313593
stable: "3.9"
1359413594
categories: [brevity, unintentional, unusedCode]
1359513595
hasPublishedDocs: false
13596+
documentation: |-
13597+
#### Description
13598+
13599+
The analyzer produces this diagnostic when `unawaited` is used to mark a
13600+
call to a function, method, or operator, or a reference to a field,
13601+
getter, or top-level variable as safely not being awaited, but the called
13602+
member is also annotated with `@awaitNotRequired`. This annotation itself
13603+
signals that wrapping with `unawaited` is unnecessary at any call site.
13604+
13605+
#### Example
13606+
13607+
The following code produces this diagnostic because `unawaited` is invoked
13608+
on a call to a function that's annotated with `@awaitNotRequired`:
13609+
13610+
```dart
13611+
import 'dart:async';
13612+
import 'package:meta/meta.dart';
13613+
13614+
@awaitNotRequired
13615+
Future<bool> log(String message) async => true;
13616+
13617+
void f() {
13618+
[!unawaited!](log('Message.'));
13619+
}
13620+
```
13621+
13622+
#### Common fixes
13623+
13624+
Remove the invocation of `unawaited`:
13625+
13626+
```dart
13627+
import 'package:meta/meta.dart';
13628+
13629+
@awaitNotRequired
13630+
Future<bool> log(String message) async => true;
13631+
13632+
void f() {
13633+
log('Message.');
13634+
}
13635+
```
1359613636
deprecatedDetails: |-
1359713637
A call to a function, method, or operator, or a reference to a field,
1359813638
getter, or top-level variable which is annotated with `@awaitNotRequired`
13599-
does not necessarily need to be awaited, nor does it need to be wrapped in
13600-
a call to `unawaited()`.
13639+
does not need to be wrapped in a call to `unawaited()`.
1360113640
1360213641
**BAD:**
1360313642
```dart

0 commit comments

Comments
 (0)