SwiftLint 사용해보기

마이노·2023년 3월 5일
0

오늘 동물의숲 api를 사용하여 기능들을 차차 추가하여 앱출시까지 해보는 프로젝트를 진행하고 있습니다. 이번에 SwiftLint를 추가로 사용하고 싶어 코코아팟을 사용해보았습니다.

너무 오랜만에 코코아팟을 사용해서그런지 사용법이 기억에 나지않아 이번에 적어두기로 마음먹었습니다ㅎㅎ

Oh no, an error occurred

먼저 마주한 녀석은 요녀석인데 Podfile에 pod '블라블라'를 추가하면 찾을 수 없다고 뜹니다. 제가 사용하고있는 ruby의 버전이 너무 낮아서 생기는 오류였습니다.

curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm list known
rvm install 2.7.2
sudo gem install cocoapods

과감히 새로 설치해주었습니다.

설치를 완료하였다면 xcworkspace를 통해 타겟을 설정해주어야 합니다.

TARGETS -> Build Phases -> Run Script

${PODS_ROOT}/SwiftLint/swiftlint

작성해주고 cmd + b를 누르면... 이제 안보였던 오류들이 생겨납니다.

이렇게 설치하면서 오류들을 발견할 수 있었는데요, 이를 파일을 만들어 관리할 수 있습니다.

$ vi .swiftlint.yml

터미널에서 다음과 같이 입력하고 조건들을 적어주시면 됩니다.

only_rules:
  - colon
  - fatal_error_message
  - implicitly_unwrapped_optional
  - legacy_cggeometry_functions
  - legacy_constant
  - legacy_constructor
  - legacy_nsgeometry_functions
  - operator_usage_whitespace
  - return_arrow_whitespace
  - trailing_newline
  - unused_optional_binding
  - vertical_whitespace
  - void_return
  - custom_rules

excluded:
  - Carthage
  - Pods

colon:
  apply_to_dictionaries: false

indentation: 2

custom_rules:
  no_objcMembers:
    name: "@objcMembers"
    regex: "@objcMembers"
    message: "Explicitly use @objc on each member you want to expose to Objective-C"
    severity: error
  no_direct_standard_out_logs:
    name: "Writing log messages directly to standard out is disallowed"
    regex: "(\\bprint|\\bdebugPrint|\\bdump|Swift\\.print|Swift\\.debugPrint|Swift\\.dump)\\s*\\("
    match_kinds:
    - identifier
    message: "Don't commit `print(…)`, `debugPrint(…)`, or `dump(…)` as they write to standard out in release. Either log to a dedicated logging system or silence this warning in debug-only scenarios explicitly using `// swiftlint:disable:next no_direct_standard_out_logs`"
    severity: warning

이를 정하는 것은 팀마다 다르기 때문에 우리팀에서는 이번에 ~~를 룰로 정하자 등의 방법을 파일을 만듬으로써 해결할 수 있게 되는 것 입니다. 저도 이번 팀 프로젝트를 진행하고 있는 것이 있는데 Swiftlint를 적용해봐야겠습니다.

profile
아요쓰 정벅하기🐥

0개의 댓글