Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneccessary module import changes. WIP #2

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Sources/unnecessary-testable/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private let kProtocolChildrenTypes: [SymbolKind] = [
.instanceProperty, .classProperty, .staticProperty,
]
private let testableRegex = try NSRegularExpression(
pattern: "^\\@testable import ([^ .]+)$", options: [.anchorsMatchLines])
pattern: "^\\import ([^ .]+)$", options: [.anchorsMatchLines])

private func getTestableImports(path: String) -> Set<String> {
guard let searchText = try? String(contentsOfFile: path) else {
Expand Down Expand Up @@ -185,16 +185,15 @@ func main(indexStorePath: String) {
occurrence.symbol.name.contains("I18N") ||
(occurrence.roles.contains(.definition) &&
referencedUSRs.contains(occurrence.symbol.usr) &&
!isChildOfProtocol(occurrence: occurrence) &&
!isPublic(file: dependentUnit.mainFile, occurrence: occurrence))
!isChildOfProtocol(occurrence: occurrence))
{
requiredTestableImports.insert(moduleName)
}
}
}

for module in testableImports.intersection(seenModules).subtracting(requiredTestableImports) {
print("/usr/bin/sed -i \"\" 's/^@testable import \(module)$/import \(module)/g' \(unitReader.mainFile)")
print("/usr/bin/sed -i \"\" '/^import \(module)$/d' \(unitReader.mainFile)")
}
}
}
Expand Down