SwiftLint
SwiftLint copied to clipboard
Allow @TestState properties be declared inside describe and context
New Issue Checklist
- [x] I've Updated SwiftLint to the latest version.
- [x] I've searched for existing GitHub issues.
Feature or Enhancement Proposal
Quick has a property wrapper called TestState which warrants there's no shared state between multiple tests by assigning the wrapped value to nil before each run.
However, the following example would trigger a quick_discouraged_call warning.
class TotoTests: QuickSpec {
override func spec() {
describe("foo") {
@TestState var foo: Foo! = Foo() // <- triggers a warning
context("bar") {
@TestState var bar: Bar! = .init() // <- triggers a warning
it("does something") {
bar.toto()
}
}
}
}
}
That's because the property is getting assigning by calling a function inside a describe/context.
I was wondering if it makes sense to not trigger when a using @TestState property. I can even look into putting up a PR (and appreciate any suggestion that can help me).
I'm not familiar with Quick, but what you describe and what I see in the implementation of @TestState in the Quick repository is that initializers are encouraged at this place. So this sounds like a reasonable exclusion.