Skip to content

Commit

Permalink
Ignore non-protocol types from redundant protocol conformance replace…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
ileitch committed Jan 2, 2024
1 parent c2d32dc commit 8264227
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Sources/PeripheryKit/ScanResultBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public struct ScanResultBuilder {
let annotatedAssignOnlyProperties: [ScanResult] = assignOnlyProperties.map {
.init(declaration: $0, annotation: .assignOnlyProperty)
}
let annotatedRedundantProtocols: [ScanResult] = redundantProtocols.map {
let inherited = graph.inheritedTypeReferences(of: $0.0).compactMapSet { $0.name }
return .init(declaration: $0.0, annotation: .redundantProtocol(references: $0.1, inherited: inherited))
let annotatedRedundantProtocols: [ScanResult] = redundantProtocols.map { decl, tuple in
let (references, inherited) = tuple
let inheritedNames = inherited.compactMapSet { $0.name }
return .init(declaration: decl, annotation: .redundantProtocol(references: references, inherited: inheritedNames))
}
let annotatedRedundantPublicAccessibility: [ScanResult] = redundantPublicAccessibility.map {
.init(declaration: $0.0, annotation: .redundantPublicAccessibility(modules: $0.1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ final class RedundantProtocolMarker: SourceGraphMutator {

if areAllReferencesConformances {
// The protocol is redundant.
graph.markRedundantProtocol(protocolDecl, references: protocolReferences)
let inherited = graph.inheritedTypeReferences(of: protocolDecl).filter { $0.kind == .protocol }
graph.markRedundantProtocol(protocolDecl, references: protocolReferences, inherited: inherited)
protocolDecl.declarations.forEach { graph.markIgnored($0) }
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/PeripheryKit/SourceGraph/SourceGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class SourceGraph {

private(set) var allDeclarations: Set<Declaration> = []
private(set) var usedDeclarations: Set<Declaration> = []
private(set) var redundantProtocols: [Declaration: Set<Reference>] = [:]
private(set) var redundantProtocols: [Declaration: (references: Set<Reference>, inherited: Set<Reference>)] = [:]
private(set) var rootDeclarations: Set<Declaration> = []
private(set) var redundantPublicAccessibility: [Declaration: Set<String>] = [:]
private(set) var rootReferences: Set<Reference> = []
Expand Down Expand Up @@ -65,9 +65,9 @@ public final class SourceGraph {
decl.usrs.contains { !allReferencesByUsr[$0, default: []].isEmpty }
}

func markRedundantProtocol(_ declaration: Declaration, references: Set<Reference>) {
func markRedundantProtocol(_ declaration: Declaration, references: Set<Reference>, inherited: Set<Reference>) {
withLock {
redundantProtocols[declaration] = references
redundantProtocols[declaration] = (references, inherited)
}
}

Expand Down

0 comments on commit 8264227

Please sign in to comment.