SwiftLint
SwiftLint copied to clipboard
Detect redundant extensions
New rule request
extension without any function will be avoid
Bad
extension Dog {}
I would be interested in how regular you really stumble upon empty extensions. Have you seen this often, @inotetw?
I often find the code such as following, may be my team coder use xcode template to generate code
// MARK: UITableViewDelegate extension TableVM: UITableViewDelegate {}
I will take on this Issue.
Its a first attempt based on variable and function declarations. There are more cases that needs to be address as well. A part from variable and function declarations, extensions can have other declarations as well. Any suggestions?
@mzeeshanid you could also check for type declarations (structs, enums, classes), and perhaps associated types and type aliases?
Also idk if subscripts count as function declaration in SwiftSyntax but if not you could check for those as well 🙂
I found a 1 liner solution i.e. if memberBlock is empty then the extension is redundant. See the last commit :)
Oh neat. Good one! 👏