0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftPMのプラグインを使ってSwiftLintを実行

Last updated at Posted at 2024-09-25

Xcodeの手順

  • XcodeのSwiftPMからSwiftLintを追加
# 下記いずれか指定(READMEでは後者が推奨されている)
https://github.com/realm/SwiftLint
https://github.com/SimplyDanny/SwiftLintPlugins

https://github.com/realm/SwiftLint
image.png

image

  • Add to TargetをNoneにしてAdd Package
  • あくまでビルド時のツールとして利用するだけで、ビルドするバイナリには含めないため

image

  • Run Build Tool Plug-insに追加

image

  • .xcodeprojと同じ階層に.swiftlint.ymlを配置

image

  • 以上でビルドを行ってwarningがでていればOK!

image

リモートのymlファイルは現状利用不可

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?