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 2025-04-19

手順

.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "<version>")
  • またTargets毎に下記を追加

Swift Package Projects
Build tool plugins run when building each target. When a project has multiple targets, the plugin must be added to the desired targets individually.

To do this, add the plugin to the target(s) to be linted as follows:

.target(
    ...
    plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")]
),
  • またSwiftLintのプラグインに最低OSの制限があり、ビルドエラーになるので最低OSの設定を追加
platforms: [
    .iOS(.v17),
    .macOS(.v15)
],
  • まとめると以下の通りです
// swift-tools-version: 6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "IKEHGitHubAPIClient",
    platforms: [
        .iOS(.v17),
        .macOS(.v15)
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "IKEHGitHubAPIClient",
            targets: ["IKEHGitHubAPIClient"]),
    ],
    dependencies: [
        .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.1.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "IKEHGitHubAPIClient",
            dependencies: [],
            plugins: [
                .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
            ],
        ),
        .testTarget(
            name: "IKEHGitHubAPIClientTests",
            dependencies: ["IKEHGitHubAPIClient"],
            plugins: [
                .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
            ],
        ),
    ]
)
  • 以上の設定を行い、ビルドして警告がでれば成功です!

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?