diff --git a/lib/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart b/lib/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart index 851ab906..4a61352c 100644 --- a/lib/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart +++ b/lib/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart @@ -8,7 +8,7 @@ import 'package:solid_lints/models/solid_lint_rule.dart'; /// or build methods and when it's called from a sync method that is called /// inside those methods. class AvoidUnnecessarySetStateRule extends SolidLintRule { - /// The [LintCode] of this lint rule that represents + /// The lint name of this lint rule that represents /// the error whether we use setState in inappropriate way. static const lintName = 'avoid_unnecessary_setstate'; diff --git a/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_method_visitor.dart b/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_method_visitor.dart index 2fe80bae..36546be8 100644 --- a/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_method_visitor.dart +++ b/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_method_visitor.dart @@ -31,15 +31,10 @@ class AvoidUnnecessarySetStateMethodVisitor extends RecursiveAstVisitor { final Iterable _bodies; final _setStateInvocations = []; - final _classMethodsInvocations = []; /// All setState invocations Iterable get setStateInvocations => _setStateInvocations; - /// All sync method invocations with setState inside - Iterable get classMethodsInvocations => - _classMethodsInvocations; - /// Constructor for AvoidUnnecessarySetStateMethodVisitor AvoidUnnecessarySetStateMethodVisitor(this._classMethodsNames, this._bodies); @@ -55,7 +50,7 @@ class AvoidUnnecessarySetStateMethodVisitor extends RecursiveAstVisitor { } else if (_classMethodsNames.contains(name) && notInBody && node.realTarget == null) { - _classMethodsInvocations.add(node); + _setStateInvocations.add(node); } } diff --git a/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_visitor.dart b/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_visitor.dart index b1682f8c..b9d79824 100644 --- a/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_visitor.dart +++ b/lib/lints/avoid_unnecessary_setstate/visitor/avoid_unnecessary_set_state_visitor.dart @@ -56,11 +56,6 @@ class AvoidUnnecessarySetStateVisitor extends RecursiveAstVisitor { final methods = declarations .where((member) => _checkedMethods.contains(member.name.lexeme)) .toList(); - final restMethods = declarations - .where((member) => !_checkedMethods.contains(member.name.lexeme)) - .toList(); - - final visitedRestMethods = {}; for (final method in methods) { final visitor = @@ -69,46 +64,7 @@ class AvoidUnnecessarySetStateVisitor extends RecursiveAstVisitor { _setStateInvocations.addAll([ ...visitor.setStateInvocations, - ...visitor.classMethodsInvocations - .where( - (invocation) => _containsSetState( - visitedRestMethods, - classMethodsNames, - bodies, - restMethods.firstWhere( - (method) => method.name.lexeme == invocation.methodName.name, - ), - ), - ) - .toList(), ]); } } - - bool _containsSetState( - Map visitedRestMethods, - Set classMethodsNames, - Iterable bodies, - MethodDeclaration declaration, - ) { - final type = declaration.returnType?.type; - if (type != null && (type.isDartAsyncFuture || type.isDartAsyncFutureOr)) { - return false; - } - - final name = declaration.name.lexeme; - if (visitedRestMethods.containsKey(name) && visitedRestMethods[name]!) { - return true; - } - - final visitor = - AvoidUnnecessarySetStateMethodVisitor(classMethodsNames, bodies); - declaration.visitChildren(visitor); - - final hasSetState = visitor.setStateInvocations.isNotEmpty; - - visitedRestMethods[name] = hasSetState; - - return hasSetState; - } }