Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to run SwiftLint for our Swift package

Tags:

So far what I found is this blog article: It's time to use Swift Package Manager which recommends integrate SwiftLint and other tools with Package.swift.

I was able to add dependency to the package file, build and test successfully but SwiftLint never warns me about syntax violations.

Before we used this Build Phases step in Xcode project:

if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

The article suggests adopting Komondor which itself useless without PackageConfigs. The idea is to run SwiftLint command during commit. I have tried to add both projects and couldn't get it working in reasonable amount of time. During commit, I see warnings like this:

Illegal instruction: 4 $komondor run pre-commit

This is still early days for Swift Package Manager and there's almost no information on the internet.

Ideally I would like to have any solution which allows our team to automate SwiftLint, and ideally that wouldn't require adding 22 dependencies, config files, and require dynamic library.

like image 498
Boris Y. Avatar asked Aug 21 '19 10:08

Boris Y.


People also ask

How do I run a Swift package?

To create a new Swift package, open Xcode and select File > New > Swift Package. Choose a name and select a file location. Select “Create Git repository on my Mac” to put your package under version control. On completion, the Swift package opens in Xcode and looks similar to a standard Xcode project.


1 Answers

A proposal in Swift, called Package Manager Extensible Build Tools (SE-0303) has been implemented, and is available in Swift 5.6, which is not yet released, as of October 2021.

A new target type, plugin (alongside executable and library) will be available to configure commands during the build. This means SwiftLint has some work to be a Swift package plugin. The SwiftLint authors could implement a package plugin that creates a command to run Swiftlint before the build.


I'll update when this proposal is implemented, and also when SwiftLint supports Extensible Build Tools

like image 100
Ben Butterworth Avatar answered Sep 19 '22 14:09

Ben Butterworth