Reputation: 11
I'm trying to create a custom SwiftLint rule to enforce documentation for functions that throw errors in Swift. Specifically, I want to check that:
So both these variants would pass:
/// - Throws: `SlothError.tooMuchFood` if the quantity is more than 100.
mutating public func eat(_ food: Food, quantity: Int) throws -> Int {
/// - Throws: `SlothError.tooMuchFood` if the quantity is more than 100.
///
mutating public func eat(_ food: Food, quantity: Int) throws -> Int {
But I'm struggling negative lookbehind for multiple lines
I have a working version of the rule that checks for functions that throw errors:
func_throw_doc:
regex: '(?<!)(func[^\n]*throws)'
message: "Add Error Throwing Documentation"
severity: warning
However, I need assistance in refining this rule to enforce the two documentation conditions mentioned.
Does anyone have experience creating more complex custom rules for SwiftLint? Any guidance on how to implement this or examples of similar rules would be greatly appreciated! Thank you!
Upvotes: 0
Views: 49