Notice
Recent Posts
Recent Comments
Link
관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - Swift] SwiftLint 적용 방법 (warning build: Run script build phase 'SwiftLint' will be run during... 해결방법) 본문

iOS 응용 (swift)

[iOS - Swift] SwiftLint 적용 방법 (warning build: Run script build phase 'SwiftLint' will be run during... 해결방법)

jake-kim 2022. 12. 4. 22:57

SwiftLint 사용 방법

  • Swiftlint는 Cocoapods으로 프로젝트에 추가하지말고 로컬에서 실행해서 사용
    • SwiftLint는 Cocoapods으로 프로젝트에 추가해서 사용할 수 있지만, 로컬에서 Swiftlint를 실행해도 사용할 수 있으므로 불필요한 cocoapods 디펜던시 주지 않기 위함
  • brew로 SwiftLint 설치
brew install swiftlint
  • Xcode -> Build Phases -> New Run Script Phase 추가하여 아래 코드 입력

(코드출처)

export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint >/dev/null; then
    swiftlint
else 
    echo "[warning] SwiftLint not installed, download using `brew install swiftlint`"
fi
  • SwiftLint 정의
    • root 타겟 선택 후 Empty 파일 생성

  • 파일 이름은 .swiftlint.yml 

  • included와 excluded로 린트를 적용할 범위 선택
included:
  - ExSwiftLint
excluded:
  - Pods
  • only_rules 로 린트 옵션 선언
    • 여기 를 참고하여 옵션 확인
    • 강제 unwrapping에 관해 warning을 주고 싶은 경우 아래처럼 선언
included:
  - ExSwiftLint
excluded:
  - Pods

only_rules:
  # stability
  - force_cast
  - force_try
  - force_unwrapping
  • 실행시 wraning 메시지 확인

warning build: Run... 해결 방법

  • 위에서 빌드하면 Xcode 14부터 경고 메시지가 등장
    • 빌드할때마다 SwiftLint가 실행되는데, 구체적으로 어떤 것을 출력해야할지 지정하지 않았으므로 경고 메시지가 출력

warning 메시지)

Run script build phase 'SwiftLint' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.

  • Based on dependency analysis 체크 해제하여 해결

* 참고

https://realm.github.io/SwiftLint/rule-directory.html

https://stackoverflow.com/questions/69449804/what-should-be-the-path-of-swiftlint-when-installed-with-swift-package-dependenc

https://github.com/realm/SwiftLint/issues/4015

 

Comments