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

Commit 0054192

Browse files
committed
fix: spurious false positives
1 parent 9a05b09 commit 0054192

File tree

1 file changed

+10
-14
lines changed
  • lib/src/analyzers/lint_analyzer/rules/rules_list/use_setstate_synchronously

1 file changed

+10
-14
lines changed

lib/src/analyzers/lint_analyzer/rules/rules_list/use_setstate_synchronously/visitor.dart

+10-14
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@ class _Visitor extends RecursiveAstVisitor<void> {
66
@override
77
void visitClassDeclaration(ClassDeclaration node) {
88
if (isWidgetStateOrSubclass(node.extendsClause?.superclass.type)) {
9-
final visitor = _AsyncSetStateVisitor();
10-
node.visitChildren(visitor);
11-
nodes.addAll(visitor.nodes);
9+
node.visitChildren(this);
1210
}
1311
}
12+
13+
@override
14+
void visitBlockFunctionBody(BlockFunctionBody node) {
15+
final visitor = _AsyncSetStateVisitor();
16+
node.visitChildren(visitor);
17+
nodes.addAll(visitor.nodes);
18+
}
1419
}
1520

1621
class _AsyncSetStateVisitor extends RecursiveAstVisitor<void> {
1722
MountedFact mounted = true.asFact();
18-
bool inFlow = false;
1923
final nodes = <SimpleIdentifier>[];
2024

21-
@override
22-
void visitBlockFunctionBody(BlockFunctionBody node) {
23-
final oldMounted = mounted;
24-
mounted = true.asFact();
25-
node.visitChildren(this);
26-
mounted = oldMounted;
27-
}
28-
2925
@override
3026
void visitAwaitExpression(AwaitExpression node) {
3127
mounted = false.asFact();
@@ -60,12 +56,12 @@ class _AsyncSetStateVisitor extends RecursiveAstVisitor<void> {
6056
final elseStatement = node.elseStatement;
6157
if (elseStatement != null) {
6258
elseDiverges = _blockDiverges(elseStatement);
63-
mounted = _tryInvert(newMounted);
59+
mounted = _tryInvert(newMounted).or(mounted);
6460
elseStatement.visitChildren(this);
6561
}
6662

6763
if (_blockDiverges(node.thenStatement)) {
68-
mounted = _tryInvert(newMounted);
64+
mounted = _tryInvert(newMounted).or(beforeThen);
6965
} else if (elseDiverges) {
7066
mounted = beforeThen != afterThen
7167
? afterThen

0 commit comments

Comments
 (0)