From 7655694ce1f7120f9af76ecc8e4aef14a68edb04 Mon Sep 17 00:00:00 2001 From: Mathias Quintero Date: Mon, 25 Jan 2021 18:40:33 +0100 Subject: [PATCH] Allowing member acccess to mark a property as used --- .../Diagnostics/UnusedWarningDiagnoser.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/Graphaello/Processing/Pipeline/Diagnostics/UnusedWarningDiagnoser.swift b/Sources/Graphaello/Processing/Pipeline/Diagnostics/UnusedWarningDiagnoser.swift index b5e7738..14456a7 100644 --- a/Sources/Graphaello/Processing/Pipeline/Diagnostics/UnusedWarningDiagnoser.swift +++ b/Sources/Graphaello/Processing/Pipeline/Diagnostics/UnusedWarningDiagnoser.swift @@ -24,8 +24,12 @@ struct UnusedWarningDiagnoser: WarningDiagnoser { verifier.walk(syntax) guard !verifier.isUsed else { return [] } - return [Warning(location: property.code.location, - descriptionText: "Unused Property `\(property.name)` belongs to a View and is fetching data from GraphQL. This can be wasteful. Consider using it or removing the property.")] + return [ + Warning( + location: property.code.location, + descriptionText: "Unused Property `\(property.name)` belongs to a View and is fetching data from GraphQL. This can be wasteful. Consider using it or removing the property." + ) + ] } } @@ -45,4 +49,13 @@ class UsageVerifier: SyntaxVisitor { isUsed = true } } + + override func visitPost(_ node: MemberAccessExprSyntax) { + if node.name.text == property.name, + let parent = node.base?.as(IdentifierExprSyntax.self), + parent.identifier.tokenKind == .selfKeyword { + + isUsed = true + } + } }