Hi everyone, we’ve just released the first version of Harmonize, a modern, open-source linter for Swift that lets your team enforce architecture and best practices through lint rules written as unit tests, using Quick, XCTest, or Swift Testing.
With Harmonize, you no longer need to rely on manual code reviews or complex regex-based SwiftLint rules.
Here’s an example rule that enforces all ViewModels to inherit from BaseViewModel
:
final class ViewModelsInheritBaseViewModelSpec: QuickSpec {
override func spec() {
describe("ViewModels") {
let viewModels = Harmonize.productionCode().classes()
.withNameEndingWith("ViewModel")
it("should inherit from BaseViewModel") {
viewModels.assertTrue(message: "All ViewModels must inherit from BaseViewModel") {
$0.inherits(from: "BaseViewModel")
}
}
}
}
}
And here’s one that enforces self
to be captured weakly in closures of ViewModels:
describe("ViewModel functions") {
let viewModelFunctions = Harmonize.productionCode().classes()
.withNameEndingWith("ViewModel")
.functions()
it("should capture self weakly in closures") {
viewModelFunctions.assertTrue {
$0.closures().filter(\.hasSelfReference).allSatisfy {
$0.isCapturingWeak(valueOf: "self")
}
}
}
}
This is the GitHub repository if you’d like to try Harmonize in your iOS project
And here’s an intro article that will walk you through it: Goodbye Code Reviews, Hello Harmonize: Enforce Your Architecture in Swift | ITNEXT
We’d love your feedback, ideas, and contributions!