Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit c4e83d1

Browse files
authored
test: add more test cases for avoid-ignoring-return-values rule (#628)
* test: add more test cases for `avoid-ignoring-return-values` rule * test: add more test cases for `avoid-ignoring-return-values` rule
1 parent 9b79547 commit c4e83d1

File tree

2 files changed

+102
-27
lines changed

2 files changed

+102
-27
lines changed

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_ignoring_return_values/avoid_ignoring_return_values_rule_test.dart

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,56 @@ void main() {
2727
RuleTestHelper.verifyIssues(
2828
issues: issues,
2929
startOffsets: [
30-
256,
31-
386,
32-
427,
33-
480,
34-
593,
35-
650,
36-
922,
37-
946,
38-
1010,
39-
1541,
40-
1598,
30+
455,
31+
585,
32+
626,
33+
759,
34+
916,
35+
973,
36+
1245,
37+
1269,
38+
1334,
39+
1360,
40+
1537,
41+
1679,
42+
1872,
43+
2888,
44+
2945,
4145
],
42-
startLines: [20, 28, 30, 33, 38, 41, 54, 55, 61, 101, 104],
43-
startColumns: [5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3],
46+
startLines: [
47+
22,
48+
30,
49+
32,
50+
37,
51+
43,
52+
46,
53+
59,
54+
60,
55+
66,
56+
68,
57+
73,
58+
77,
59+
82,
60+
144,
61+
147,
62+
],
63+
startColumns: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3],
4464
endOffsets: [
45-
271,
46-
413,
47-
442,
48-
501,
49-
610,
50-
673,
65+
470,
66+
612,
67+
641,
68+
780,
5169
933,
52-
957,
53-
1022,
54-
1552,
55-
1625,
70+
996,
71+
1256,
72+
1281,
73+
1346,
74+
1386,
75+
1569,
76+
1709,
77+
1908,
78+
2899,
79+
2972,
5680
],
5781
locationTexts: [
5882
'list.remove(1);',
@@ -62,8 +86,12 @@ void main() {
6286
'futureOrMethod();',
6387
'await futureOrMethod();',
6488
'props.name;',
65-
'props.name;',
89+
'props.value;',
6690
'props.field;',
91+
'props.futureMixinMethod();',
92+
'await props.futureMixinMethod();',
93+
'props.futureExtensionMethod();',
94+
'await props.futureExtensionMethod();',
6795
'function();',
6896
'SomeService.staticMethod();',
6997
],
@@ -79,6 +107,10 @@ void main() {
79107
'Avoid ignoring return values.',
80108
'Avoid ignoring return values.',
81109
'Avoid ignoring return values.',
110+
'Avoid ignoring return values.',
111+
'Avoid ignoring return values.',
112+
'Avoid ignoring return values.',
113+
'Avoid ignoring return values.',
82114
],
83115
);
84116
});

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_ignoring_return_values/examples/example.dart

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: prefer_expression_function_bodies, unawaited_futures, cascade_invocations, unused_local_variable, unnecessary_statements, prefer_void_to_null, return_without_value
2+
13
import 'dart:async';
24

35
class SomeService {
@@ -9,7 +11,7 @@ class SomeService {
911
return 'string';
1012
}
1113

12-
void voidMethod() {
14+
Future<void> voidMethod() async {
1315
final list = [
1416
1,
1517
2,
@@ -28,9 +30,12 @@ class SomeService {
2830
(list..sort()).contains(1); // LINT
2931

3032
futureMethod(); // LINT
33+
futureMethod().then((_) => null);
3134
voidFutureMethod();
35+
voidFutureMethod().then((_) => null);
3236

3337
await futureMethod(); // LINT
38+
await futureMethod().then((_) => null);
3439
await voidFutureMethod();
3540

3641
final futureResult = await futureMethod();
@@ -52,13 +57,31 @@ class SomeService {
5257
final props = ClassWithProps();
5358

5459
props.name; // LINT
55-
props.name; // LINT
60+
props.value; // LINT
5661

5762
props
5863
..name
5964
..value;
6065

6166
props.field; // LINT
67+
68+
props.futureMixinMethod(); // LINT
69+
props.futureMixinMethod().then((_) => null);
70+
props.voidFutureMixinMethod();
71+
props.voidFutureMixinMethod().then((_) => null);
72+
73+
await props.futureMixinMethod(); // LINT
74+
await props.futureMixinMethod().then((_) => null);
75+
await props.voidFutureMixinMethod();
76+
77+
props.futureExtensionMethod(); // LINT
78+
props.futureExtensionMethod().then((_) => null);
79+
props.voidFutureExtensionMethod();
80+
props.voidFutureExtensionMethod().then((_) => null);
81+
82+
await props.futureExtensionMethod(); // LINT
83+
await props.futureExtensionMethod().then((_) => null);
84+
await props.voidFutureExtensionMethod();
6285
}
6386

6487
Future<int> futureMethod() async {
@@ -86,13 +109,33 @@ class SomeService {
86109
}
87110
}
88111

89-
class ClassWithProps {
112+
class ClassWithProps with MixinWithProp {
90113
String get name => 'name';
91114
String get value => 'value';
92115

93116
String field = 'field';
94117
}
95118

119+
mixin MixinWithProp {
120+
Future<int> futureMixinMethod() async {
121+
return 1;
122+
}
123+
124+
Future<void> voidFutureMixinMethod() async {
125+
return;
126+
}
127+
}
128+
129+
extension ClassWithPropsExtension on ClassWithProps {
130+
Future<int> futureExtensionMethod() async {
131+
return 1;
132+
}
133+
134+
Future<void> voidFutureExtensionMethod() async {
135+
return;
136+
}
137+
}
138+
96139
String function() {
97140
return 'string';
98141
}

0 commit comments

Comments
 (0)