Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 513
bencallis Avatar asked Sep 19 '18 16:09

bencallis


People also ask

How to disable rules in SwiftLint?

Option 2: Disable Rules at Source Level:let noWarning :String = "" // No warning about colons immediately after variable names! let noWarning :String = "" // No warning about colons immediately after variable names!

How do I change a rule in Swiftlint?

Personally, I fire up Terminal, cd into the root directory of my project, and type touch . swiftlint. yml to create a blank file. Then go to your text editor of choice and add whatever rules you want (see the README for some examples, perhaps copy-and-paste some examples into your file).

How to disable unit test in Swift?

One of the quickest ways to disable a unit test is to simply rename its name. Xcode will execute only those test methods that start with a prefix “test”. If a method name does not start with a test prefix, it will not be executed.

Where do I put Swiftlint Yml?

swiftlint. yml file to your project directory. Note that this file should be added alongside your Xcode project and your Xcode workspace. It should not be placed inside of your project files directory.


1 Answers

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
like image 115
Durdu Avatar answered Sep 23 '22 17:09

Durdu