Enumerations
Unused Enum Cases
Section titled “Unused Enum Cases”Along with being able to identify unused enumerations, Periphery can also identify individual unused enum cases. Plain enums that are not raw representable, i.e., that don’t have a String, Character, Int, or floating-point value type, can be reliably identified. However, enumerations that do have a raw value type can be dynamic, and therefore must be assumed to be used.
enum MyEnum: String { case myCase}
func someFunction(value: String) { if let myEnum = MyEnum(rawValue: value) { somethingImportant(myEnum) }}There’s no direct reference to the myCase case, so it’s reasonable to expect it might no longer be needed. However, if it were removed, we can see that somethingImportant would never be called if someFunction were passed the value of "myCase".
Unused Associated Values
Section titled “Unused Associated Values”Periphery can report unused associated values on an enum case that is still in use. When it can verify how the case is created and used, it reports each associated value that is never read.
enum DownloadState { case completed(image: String, originalData: [UInt8])}
if case let .completed(image, originalData) = DownloadState.completed( image: "thumbnail.png", originalData: [1, 2, 3]) { print(image)}Periphery points to originalData in the case declaration and reports the following.
Associated value 'originalData' of 'completed(image:originalData:)' is supplied but never readThis analysis is enabled by default. Disable it with --disable-unused-associated-value-analysis, or set disable_unused_associated_value_analysis: true in your configuration.