Skip to content

Commit

Permalink
fix: ignore defined_value_getter_type if return Future (#100)
Browse files Browse the repository at this point in the history
fix: ignore defined_value_getter_type when return furure
  • Loading branch information
ronnnnn authored Feb 24, 2024
1 parent 7015ddb commit c3467c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/nilts/lib/src/lints/defined_value_getter_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class DefinedValueGetterType extends DartLintRule {
final returnType = type.returnType;
if (returnType is VoidType ||
returnType is InvalidType ||
returnType is NeverType) return;
returnType is NeverType ||
returnType.isDartAsyncFuture) return;

reporter.reportErrorForNode(_code, node);
});
Expand Down
17 changes: 14 additions & 3 deletions packages/nilts_test/test/lints/defined_value_getter_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,36 @@ class MainButton extends StatelessWidget {
const MainButton(
void Function() this.onPressed,
// expect_lint: defined_value_getter_type
int Function() this.onReturnPressed, {
int Function() this.onReturnPressed,
Future<int> Function() this.onFutureReturnPressed, {
void Function()? this.onNullablePressed,
void Function(int)? this.onParamPressed,
// expect_lint: defined_value_getter_type
int Function()? this.onNullableReturnPressed,
Future<int> Function()? this.onNullableFutureReturnPressed,
super.key,
});

final void Function() onPressed;
// expect_lint: defined_value_getter_type
final int Function() onReturnPressed;
final Future<int> Function() onFutureReturnPressed;
final void Function()? onNullablePressed;
final void Function(int)? onParamPressed;
// expect_lint: defined_value_getter_type
final int Function()? onNullableReturnPressed;
final Future<int> Function()? onNullableFutureReturnPressed;

void _onPressed(
void Function() onPressed,
// expect_lint: defined_value_getter_type
int Function() onReturnPressed, {
int Function() onReturnPressed,
Future<int> Function() onFutureReturnPressed, {
void Function()? onNullablePressed,
void Function(int)? onParamPressed,
// expect_lint: defined_value_getter_type
int Function()? onNullableReturnPressed,
Future<int> Function()? onNullableFutureReturnPressed,
}) {}

@override
Expand All @@ -44,6 +50,7 @@ class MainButton extends StatelessWidget {
_onPressed(
() {},
() => 0,
() async => 0,
);
onPressed();
},
Expand All @@ -55,17 +62,21 @@ class MainButton extends StatelessWidget {
final void Function() globalFunction = () {};
// expect_lint: defined_value_getter_type
final int Function() globalReturnFunction = () => 0;
final Future<int> Function() globalFutureReturnFunction = () async => 0;
const void Function()? globalNullableFunction = null;
const void Function(int)? globalParamFunction = null;
// expect_lint: defined_value_getter_type
const int Function()? globalNullableReturnFunction = null;
const Future<int> Function()? globalNullableFutureReturnFunction = null;

void _globalFunction(
void Function() onPressed,
// expect_lint: defined_value_getter_type
int Function() onReturnPressed, {
int Function() onReturnPressed,
Future<int> Function() onFutureReturnPressed, {
void Function()? onNullablePressed,
void Function(int)? onParamPressed,
// expect_lint: defined_value_getter_type
int Function()? onNullableReturnPressed,
Future<int> Function()? onNullableFutureReturnPressed,
}) {}

0 comments on commit c3467c3

Please sign in to comment.