In this article we will explore another way to detect unused code, by using a ruby script from https://github.com/PaulTaykalo/swift-scripts.
We have already tried the periphery tool http://trikalabs.com/detect-unused-code-periphery/
And let’s follow the same steps as we did for periphery in order to compare them!
- Let’s create a project and name it UnusedCodeTest.
- Next let’s add an unused class in the target:
123class UnusedClass {}
- Also we add an unused method, a used method and a used method with an unused parameter:
123456789101112131415161718192021222324struct ContentView: View {var body: some View {VStack {Text("Hello, world!").padding()}.onAppear(perform: {methodCalled()methodUnusedParameter(a: 3, b: 4)})}func methodCalled() {}func methodUnCalled() {}func methodUnusedParameter(a: Int, b: Int) {_ = a * a}}
Now,
- As first step let’s download the repo.
- Then lest copy the usused.rb file inside our project folder.
- Then let’s run ./unused.rb
And here are our results:
It finds all the issues we found with periphery but it also inform us about the previews, which we want actually to keep them.
Overall, another great tool!