LoginSignup
3
1

More than 1 year has passed since last update.

【Swift】MintでSwiftLintを導入する

Last updated at Posted at 2022-10-29

はじめに

SwiftLintを初めて使ってみたのでやりかたを記録しておきます

やりかた

Mintfile

ターミナル
cd プロジェクトフォルダ

Mintfileを作成します

ターミナル
touch Mintfile

Mintfileを開きます

ターミナル
open Mintfile

MintfileにLicensePlistを記載します

Mintfile
realm/SwiftLint@0.49.1

SwiftLintをインストールします

ターミナル
mint bootstrap

.swiftlint.yml

.swiftlint.ymlを作成します

ターミナル
touch .swiftlint.yml

.swiftlint.ymlを開きます

ターミナル
open .swiftlint.yml

.swiftlint.ymlを編集します
他にもたくさんルールがあるので公式のルール一覧を見てください

.swiftlint.yml
# 無効にするルール
disabled_rules:
- function_body_length
- line_length
- trailing_whitespace

# チェック対象ファイル
included:
- {プロジェクト直下のファイル名}

# Class, Struct, Enumの行数制限
type_body_length:
- 400
- 600

# 1ファイルの行数制限
file_length:
- 600
- 1000

Run Script

export PATH=/opt/homebrew/bin:$PATH

if which mint >/dev/null; then
    # SwiftLint
    xcrun --sdk macosx mint run swiftlint
else 
    echo 'warning: mint not installed.'
fi

おわり

SwiftLintは難しそうで避けていましたが、意外と簡単でびっくりしました。

3
1
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
3
1