Xcodeの手順
- XcodeのSwiftPMからSwiftLintを追加
# 下記いずれか指定(READMEでは後者が推奨されている)
https://github.com/realm/SwiftLint
https://github.com/SimplyDanny/SwiftLintPlugins
-
Add to Target
をNoneにしてAdd Package - あくまでビルド時のツールとして利用するだけで、ビルドするバイナリには含めないため
-
Run Build Tool Plug-ins
に追加
-
.xcodeproj
と同じ階層に.swiftlint.yml
を配置
- 以上でビルドを行ってwarningがでていればOK!
リモートのymlファイルは現状利用不可
-
Swift Package Manager Plugin SwiftLint Configuration Error: Unable to cache remote config #4787
- 現状リモートに配置している
.swiftlint.yml
は利用できず、下記の設定はうまくいかない - SwiftLint-Config
- 現状リモートに配置している
- Build Tool Pluginsの対応を待つ(これを自作すればいけるんでしょうか)
I just ran into this issue again, and it looks like as of SwiftPM 5.9 a plugin can add a permission to allow network connections: https://developer.apple.com/documentation/packagedescription/pluginpermission/allownetworkconnections(scope:reason:)
This permission can only be added to Command Plugins. This issue is about Build Tool Plugins though.
GitHub Actionsでの実行
-
<path-to-root>/.github/workflows/run-swiftlint.yml
を作成 - warningの場合も成功してしまうので、
swiftlint --strict
とオプションをつけている
name: SwiftLint
on:
workflow_dispatch:
pull_request:
push:
branches:
- main # 実行したいブランチを指定
jobs:
swiftlint:
runs-on: macos-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
# Homebrewのキャッシュを利用
- name: Cache Homebrew
uses: actions/cache@v3
with:
path: /usr/local/Homebrew
key: ${{ runner.os }}-brew-${{ hashFiles('**/Brewfile') }}
restore-keys: |
${{ runner.os }}-brew-
# SwiftLintのインストール
- name: Install SwiftLint
run: brew install swiftlint
# SwiftLintを実行
- name: Run SwiftLint
run: swiftlint --strict