swiftunit-testingxctestswiftlint

Disable some SwiftLint rules for test target/unit tests files


I am looking to disable a couple of SwiftLint rules for the unit tests within my application.

For example I am wanting to disable the weak_delegate rule for my unit tests.

Having looked at the SwiftLint docs I think it may be possible by defining a custom weak_delegate rule and excluding the path to my unit tests.

https://github.com/realm/SwiftLint#defining-custom-rules


Solution

  • You can disable them at a local level using:

    //swiftlint:disable weak_delegate
    let someDelete: someDelegate?
    //swiftlint:enable weak_delegate
    

    or at target level, by modifying your .swiftlint.yml file (hidden)

    weak_delegate:
        excluded: ".*Test\\.swift" //regex path to your tests folder
    

    or at project level, by modifying your .swiftlint.yml file (hidden)

    disabled_rules:
     - weak_delegate