Skip to content

Commit

Permalink
Merge pull request #137 from rubenlop88/trunk
Browse files Browse the repository at this point in the history
Skip named types used in Widget State class declarations
  • Loading branch information
santitigaga authored Sep 4, 2024
2 parents 4db0a50 + fb3574e commit 2dd7f28
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/analyzers/unused_code_analyzer/used_code_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class UsedCodeVisitor extends RecursiveAstVisitor<void> {

@override
void visitNamedType(NamedType node) {
if (_isUsedInWidgetStateClassDeclaration(node)) {
return;
}
_recordPrefixedElement(node.importPrefix, node.element);
super.visitNamedType(node);
}
Expand Down Expand Up @@ -244,4 +247,14 @@ class UsedCodeVisitor extends RecursiveAstVisitor<void> {
return grandGrandParent is NamedType &&
isWidgetStateOrSubclass(grandGrandParent.type);
}

bool _isUsedInWidgetStateClassDeclaration(NamedType namedType) {
final parent = namedType.parent;
if (parent is TypeArgumentList) {
final grandParent = parent.parent;
return grandParent is NamedType &&
isWidgetStateOrSubclass(grandParent.type);
}
return false;
}
}

0 comments on commit 2dd7f28

Please sign in to comment.