Trikalabs
  • Home
  • Best online TDD videos
  • Book Suggestions
  • About Me
  • Contact
Trikalabs
No Result
View All Result

Detect unused code – Periphery

by fragi
February 15, 2022
in Tools
Share on FacebookShare on Twitter

Codebases are growing over time (most of the times). They do also go after minor or major refactors. And regardless how careful or not is the team, there are often cases that there is some unused code left in the codebase.
In this article we will use the Periphery(https://github.com/peripheryapp/periphery) tool to detect unused code.

  1. Let’s create a project and name it UnusedCodeTest.
  2. Install through brew the periphery
    Swift
    1
    brew install peripheryapp/periphery/periphery
  3. Next let’s add an unused class in the target:
    Swift
    1
    2
    3
    class UnusedClass {
        
    }
  4. Also we add an unused method, a used method and a used method with an unused parameter:
    Swift
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    struct 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
        }
    }
  5. Now let’s run the command:
    Swift
    1
    periphery scan --setup

    And this will guide us through the setup:

  6. As a result we have a yml file with these details
    Swift
    1
    2
    3
    4
    5
    project: UnusedCodeTest.xcodeproj
    schemes:
    - UnusedCodeTest
    targets:
    - UnusedCodeTest
  7. Now let’s see how good is the tool:

    It found 3 out 3 issues! Not bad at all!

fragi

fragi

Related Posts

Delete Derived Data – zsh command
Tools

Delete Derived Data – zsh command

April 22, 2022

There are some times that we have to delete the derived data that Xcode produces.There are many ways to achieve...

SwiftGen – Statically reference resources
Tools

SwiftGen – Statically reference resources

February 28, 2022

In this article we can see how we can statically reference strings. Let's look on the following example: As...

Postman – Monitors
Postman

Postman – Monitors

February 27, 2022

So we have created our collection with the API request, we an up and running mock server http://trikalabs.com/postman-mock-server/  and a...

Xcode custom template
Tools

Xcode custom template

February 25, 2022

In this article we will create a template that creates a view and a viewModel files.In the previous article http://trikalabs.com/xcode-templates/...

Xcode Templates
Tools

Xcode Templates

February 24, 2022

Xcode provides with a lot of custom templates. In this article we will explore how we can change them. In...

Newman – Run Postman collections tests
Postman

Newman – Run Postman collections tests

February 27, 2022

Newman is a command-line Collection Runner for Postman. We can use newman to run postman collection tests through cli, which...

Next Post
Delete Derived Data – zsh command

Delete Derived Data - Bash command

Detect unused code – Periphery

Detect unused code – ruby script from (https://github.com/PaulTaykalo)

Accessibility by Example

Accessibility - AutoResizable views

  • Advertise
  • Privacy & Policy
  • Contact

© 2019 Trikalabs Ltd. All rights reserved.

No Result
View All Result
  • Home
  • About Me
  • A curated list with the best free online TDD videos
  • Book Suggestions
  • Pinner Code Club

© 2019 Trikalabs Ltd. All rights reserved.