SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Allow @TestState properties be declared inside describe and context

Open kasrababaei opened this issue 1 year ago • 1 comments

New Issue Checklist

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).

kasrababaei avatar Sep 20 '24 21:09 kasrababaei

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.

SimplyDanny avatar Oct 01 '24 15:10 SimplyDanny