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

fix: correctly handle dynamic type for avoid-passing-async-when-sync-expected #1189

Merged
merged 2 commits into from
Feb 12, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* fix: correctly handle `dynamic` type for [`avoid-passing-async-when-sync-expected`](https://dcm.dev/docs/individuals/rules/common/avoid-passing-async-when-sync-expected).
* fix: check `didChangeDependencies` for [`avoid-unnecessary-setstate`](https://dcm.dev/docs/individuals/rules/flutter/avoid-unnecessary-setstate).
* fix: add new config option for [`no-equal-arguments`](https://dcm.dev/docs/individuals/rules/common/no-equal-arguments).
* feat: add `allow-nullable` config option for [`avoid-returning-widgets`](https://dcm.dev/docs/individuals/rules/common/avoid-returning-widgets).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class AvoidPassingAsyncWhenSyncExpectedRule extends CommonRule {
return visitor.invalidArguments
.map((invocation) => createIssue(
rule: this,
location: nodeLocation(
node: invocation,
source: source,
),
location: nodeLocation(node: invocation, source: source),
message: _warningMessage,
))
.toList(growable: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ class _Visitor extends RecursiveAstVisitor<void> {
final parameterType = argument.staticParameterElement?.type;
if (argumentType is FunctionType && parameterType is FunctionType) {
if (argumentType.returnType.isDartAsyncFuture &&
(!parameterType.returnType.isDartAsyncFuture &&
!parameterType.returnType.isDartAsyncFutureOr)) {
!_hasValidFutureType(parameterType.returnType)) {
_invalidArguments.add(argument);
}
}
}
}

bool _hasValidFutureType(DartType type) =>
type.isDartAsyncFuture ||
type.isDartAsyncFutureOr ||
type.isDynamic ||
type.isDartCoreObject;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {

RuleTestHelper.verifyIssues(
issues: issues,
startLines: [49, 54, 57, 84],
startLines: [49, 54, 57, 87],
startColumns: [7, 7, 7, 9],
locationTexts: [
'synchronousWork: work1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _MyHomePageState extends State<MyHomePage> {
print('work 3');
},
synchronousWork4: work4, // LINT
synchronousWork5: work1,
);
}

Expand All @@ -63,11 +64,13 @@ class _MyHomePageState extends State<MyHomePage> {
required VoidCallback synchronousWork2,
required VoidCallback synchronousWork3,
required VoidCallback synchronousWork4,
required dynamic Function() synchronousWork5,
}) {
synchronousWork();
synchronousWork2();
synchronousWork3();
synchronousWork4();
synchronousWork5();
}

void _incrementCounter() {
Expand Down