DEV Community

Jakub Turek for EL Passion

Posted on

SwiftLint config per target

EL Passion ❤️ open source.

In our mission to deliver the highest quality product possible, the iOS team at EL Passion rely on linting tools such as SwiftLint to fix common code structuring & formatting issues.

However, there are some scenarios in which we can't easily employ the tooling to work for us. We've encountered this issue when developing VinylShop mobile app with the following directory structure:

Project /
├── Project.xcodeproj
└── Sources /
    └── Controllers /
       └── Login /
           ├── LoginViewController.swift
           └── LoginViewControllerSpec.swift

We couldn't easily configure SwiftLint to use a different configuration for the production and for the test files.

SwiftLint runner

Fortunately, we've been able to fix the issue by implementing a simple Python script which reads the contents of the .pbxproj file and modifies the included files in the SwiftLint config prior to the linting. The script is divided into the two simple files:

What's even better is that we've released the script as the PyPI package, so you can use it in your own projects, too. It's as simple as running:

pip install swiftlint-runner

And adding an appropriate build phase:

slrunner <project_name>.xcodeproj <target_name> .<swiftlint_config_file_name>.yml

You can find more details at the elpassion/swiftlint-runner repository.

License

SwiftLint runner is maintained with ❤️ by EL Passion and released under an MIT license.

Top comments (0)