점진적 과부하 개발 블로그

SwiftLint 알아보기 본문

Swift

SwiftLint 알아보기

지용빡 2022. 7. 4. 06:21
반응형
SwiftLint 알아보기
SwiftLint 란 
 

GitHub - realm/SwiftLint: A tool to enforce Swift style and conventions.

A tool to enforce Swift style and conventions. Contribute to realm/SwiftLint development by creating an account on GitHub.

github.com

 

  • 강제로 NSObject를 Int형으로 타입 캐스팅을 시도하는 코드이다, 만약 실패하게 되면 앱이 크래쉬가 발생되는 아주 극단적인 코드이다. 
  • 이런 코드를 SwiftLint가 강제적으로 컴파일 에러를 시켜서 Xcode가 작동을 못하게 한다.
  • 두번째 코드는 스페이스바의 위치가 잘못되어있는 경우 SwiftLint가 주의를 주는 모습을 볼 수 있습니다.

 

이것 말고도 file_length: 의 관한 줄 수도 설정할 수 있다.

file_length:
    waring: 500 // Swift 파일의 줄 수가 500줄 이상이면 경고 
    error: 1200 // Swift 파일의 줄 수가 1200줄 이상이면 error

 

 

Xcode내에 .swiftlint,yml 파일을 추가하고 아래와 같은 코드를 입력해주면 커스텀 또한 가능하다.

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
  severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
  - 300 # warning
  - 400 # error
# or they can set both explicitly
file_length:
  warning: 500
  error: 1200
반응형