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

test: add more test cases for avoid-ignoring-return-values rule #628

Merged
merged 2 commits into from
Jan 5, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,56 @@ void main() {
RuleTestHelper.verifyIssues(
issues: issues,
startOffsets: [
256,
386,
427,
480,
593,
650,
922,
946,
1010,
1541,
1598,
455,
585,
626,
759,
916,
973,
1245,
1269,
1334,
1360,
1537,
1679,
1872,
2888,
2945,
],
startLines: [20, 28, 30, 33, 38, 41, 54, 55, 61, 101, 104],
startColumns: [5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3],
startLines: [
22,
30,
32,
37,
43,
46,
59,
60,
66,
68,
73,
77,
82,
144,
147,
],
startColumns: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3],
endOffsets: [
271,
413,
442,
501,
610,
673,
470,
612,
641,
780,
933,
957,
1022,
1552,
1625,
996,
1256,
1281,
1346,
1386,
1569,
1709,
1908,
2899,
2972,
],
locationTexts: [
'list.remove(1);',
Expand All @@ -62,8 +86,12 @@ void main() {
'futureOrMethod();',
'await futureOrMethod();',
'props.name;',
'props.name;',
'props.value;',
'props.field;',
'props.futureMixinMethod();',
'await props.futureMixinMethod();',
'props.futureExtensionMethod();',
'await props.futureExtensionMethod();',
'function();',
'SomeService.staticMethod();',
],
Expand All @@ -79,6 +107,10 @@ void main() {
'Avoid ignoring return values.',
'Avoid ignoring return values.',
'Avoid ignoring return values.',
'Avoid ignoring return values.',
'Avoid ignoring return values.',
'Avoid ignoring return values.',
'Avoid ignoring return values.',
],
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: prefer_expression_function_bodies, unawaited_futures, cascade_invocations, unused_local_variable, unnecessary_statements, prefer_void_to_null, return_without_value

import 'dart:async';

class SomeService {
Expand All @@ -9,7 +11,7 @@ class SomeService {
return 'string';
}

void voidMethod() {
Future<void> voidMethod() async {
final list = [
1,
2,
Expand All @@ -28,9 +30,12 @@ class SomeService {
(list..sort()).contains(1); // LINT

futureMethod(); // LINT
futureMethod().then((_) => null);
voidFutureMethod();
voidFutureMethod().then((_) => null);

await futureMethod(); // LINT
await futureMethod().then((_) => null);
await voidFutureMethod();

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

props.name; // LINT
props.name; // LINT
props.value; // LINT

props
..name
..value;

props.field; // LINT

props.futureMixinMethod(); // LINT
props.futureMixinMethod().then((_) => null);
props.voidFutureMixinMethod();
props.voidFutureMixinMethod().then((_) => null);

await props.futureMixinMethod(); // LINT
await props.futureMixinMethod().then((_) => null);
await props.voidFutureMixinMethod();

props.futureExtensionMethod(); // LINT
props.futureExtensionMethod().then((_) => null);
props.voidFutureExtensionMethod();
props.voidFutureExtensionMethod().then((_) => null);

await props.futureExtensionMethod(); // LINT
await props.futureExtensionMethod().then((_) => null);
await props.voidFutureExtensionMethod();
}

Future<int> futureMethod() async {
Expand Down Expand Up @@ -86,13 +109,33 @@ class SomeService {
}
}

class ClassWithProps {
class ClassWithProps with MixinWithProp {
String get name => 'name';
String get value => 'value';

String field = 'field';
}

mixin MixinWithProp {
Future<int> futureMixinMethod() async {
return 1;
}

Future<void> voidFutureMixinMethod() async {
return;
}
}

extension ClassWithPropsExtension on ClassWithProps {
Future<int> futureExtensionMethod() async {
return 1;
}

Future<void> voidFutureExtensionMethod() async {
return;
}
}

String function() {
return 'string';
}
Expand Down