peripheryapp / periphery

A tool to identify unused code in Swift projects.
MIT License
5.2k stars 186 forks source link

Question: Merging different configuration results #755

Open Lommelun opened 3 months ago

Lommelun commented 3 months ago

I read this line in the readme

Run Periphery once for each build configuration and merge the results. You can pass arguments to the underlying build by specifying them after --, e.g periphery scan ... -- -configuration release.

And I'm not sure what is meant by merging the results? My understanding of this means that I get the results, then merge the results–meaning that the same individual results will be the same, while new individual results will be added together; thus in this example both will be unused?

periphery scan ... -- -configuration debug
struct BuildInfo {
    let debugName = "debug"
    let releaseName = "release" // 'releaseName' is unused

    var name: String {
        #if DEBUG
        debugName
        #else
        releaseName
        #endif
    }
}
periphery scan ... -- -configuration release
struct BuildInfo {
    let debugName = "debug" // 'debugName' is unused
    let releaseName = "release"

    var name: String {
        #if DEBUG
        debugName
        #else
        releaseName
        #endif
    }
}
... merge results ...
struct BuildInfo {
    let debugName = "debug" // 'debugName' is unused
    let releaseName = "release"  // 'releaseName' is unused

    var name: String {
        #if DEBUG
        debugName
        #else
        releaseName
        #endif
    }
}

Or am I misunderstanding how and what you mean by merging the results?

kattouf commented 3 weeks ago

I believe the intention is to use the intersection of results from all runs. Here’s how you could approach it:

  1. Run Periphery for each configuration and export the results in a machine-readable format:

    --format <format>       Output format (allowed: xcode, csv, json, checkstyle, codeclimate, github-actions) 
                           (default: xcode)
  2. Read and convert the results into arrays that are easy to compare in any language you use.

  3. Use the intersection of these arrays to find common results across all configurations.