Skip to content

Commit 1aa0e78

Browse files
authored
Detect enum cases for testable with symbol kind (#42)
1 parent 54887d3 commit 1aa0e78

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Sources/unnecessary-testable/main.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ private func isPublic(file: String, occurrence: SymbolOccurrence, isOverride: Bo
6868
return false
6969
}
7070

71-
let contents = try! String(contentsOfFile: file)
72-
let text = contents.components(separatedBy: .newlines)[occurrence.location.line - 1]
73-
7471
// enum cases aren't explicitly marked public but inherit their ACL from their type definition. This is
7572
// overly permissive since the enum could be internal, but it's very likely the file also contains a
7673
// reference to the actual enum in that case, which will correctly bet determined to be public/internal,
7774
// so it should still resolve the testable import correctly.
78-
if text.contains("case ") {
75+
if occurrence.symbol.kind == .enumConstant {
7976
return true
8077
}
8178

79+
let contents = try! String(contentsOfFile: file)
80+
let text = contents.components(separatedBy: .newlines)[occurrence.location.line - 1]
8281
let isPublic = (text.contains("public ") && !isOverride) || text.contains("open ")
8382
// Handle public members that explicitly set 'internal(set)' for allowing setting from tests
8483
return isPublic && !text.contains(" internal(")

0 commit comments

Comments
 (0)