Skip to content

Commit

Permalink
Cleanup naming
Browse files Browse the repository at this point in the history
  • Loading branch information
solid-yuriiprykhodko committed Nov 22, 2023
1 parent 05aa5da commit f73a16c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class AvoidUnnecessarySetStateRule extends SolidLintRule {
ErrorReporter reporter,
CustomLintContext context,
) {
final visitor = AvoidUnnecessarySetStateVisitor();

context.registry.addClassDeclaration((node) {
final visitor = AvoidUnnecessarySetStateVisitor();
visitor.visitClassDeclaration(node);
for (final element in visitor.setStateInvocations) {
reporter.reportErrorForNode(code, element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
/// necessary
class AvoidUnnecessarySetStateMethodVisitor extends RecursiveAstVisitor<void> {
final Set<String> _classMethodsNames;
final Iterable<FunctionBody> _bodies;
final Set<FunctionBody> _bodies;

final _setStateInvocations = <MethodInvocation>[];

Expand All @@ -47,9 +47,13 @@ class AvoidUnnecessarySetStateMethodVisitor extends RecursiveAstVisitor<void> {

if (name == 'setState' && notInBody) {
_setStateInvocations.add(node);
} else if (_classMethodsNames.contains(name) &&
notInBody &&
node.realTarget == null) {
return;
}

final isClassMethod = _classMethodsNames.contains(name);
final isReturnValueUsed = node.realTarget != null;

if (isClassMethod && notInBody && !isReturnValueUsed) {
_setStateInvocations.add(node);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class AvoidUnnecessarySetStateVisitor extends RecursiveAstVisitor<void> {
return;
}

final declarations = node.members.whereType<MethodDeclaration>().toList();
final declarations = node.members.whereType<MethodDeclaration>();
final classMethodsNames =
declarations.map((declaration) => declaration.name.lexeme).toSet();
final bodies = declarations.map((declaration) => declaration.body).toList();
final bodies = declarations.map((declaration) => declaration.body).toSet();
final methods = declarations
.where((member) => _checkedMethods.contains(member.name.lexeme))
.toList();
Expand Down

0 comments on commit f73a16c

Please sign in to comment.