Skip to content

iOS Convention

SeungHyun Hong edited this page Nov 23, 2023 · 6 revisions

✅ swiftLint 적용

airbnb의 코드 컨벤션이 저희 모두가 생각하는 컨벤션 방향과 맞다고 판단하여 해당 Lint를 가져와서 사용하게 되었습니다!

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
  - unowned_variable_capture
  - custom_rules
  - trailing_comma
  - line_length

excluded:
  - Carthage
  - Pods
  - .build

colon:
  apply_to_dictionaries: false

indentation: 2

trailing_comma:
  mandatory_comma: true
  
line_length:
  warning: 150

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: error
  no_file_literal:
    name: "#file is disallowed"
    regex: "(\\b#file\\b)"
    match_kinds:
    - identifier
    message: "Instead of #file, use #fileID"
    severity: error
  no_filepath_literal:
    name: "#filePath is disallowed"
    regex: "(\\b#filePath\\b)"
    match_kinds:
    - identifier
    message: "Instead of #filePath, use #fileID."
    severity: error
  no_unchecked_sendable:
    name: "`@unchecked Sendable` is discouraged."
    regex: "@unchecked Sendable"
    match_kinds:
    - attribute.builtin
    - typeidentifier
    message: "Instead of using `@unchecked Sendable`, consider a safe alternative like a standard `Sendable` conformance or using `@preconcurrency import`. If you really must use `@unchecked Sendable`, you can add a `// swiftlint:disable:next no_unchecked_sendable` annotation with an explanation for how we know the type is thread-safe, and why we have to use @unchecked Sendable instead of Sendable. More explanation and suggested safe alternatives are available at https://github.com/airbnb/swift#unchecked-sendable."
    severity: error

✅ swiftFormat 적용

팀 내부에서 적용하면 좋을 것 같은 형식 위주로 구성했습니다!

--swiftversion 5.9

# format options

--indent 2
--selfrequired
--importgrouping alpha
--enable acronyms
--acronyms "URL, ID, UUID"
--enable blankLineAfterImports
--enable blankLinesAroundMark
--enable blockComments
--enable docComments
--enable isEmpty
--enable markTypes
--enable sortSwitchCases
--enable wrapEnumCases
--enable wrapSwitchCases
--guardelse "next-line"

--disable wrapMultilineStatementBraces
--disable andOperator
--disable redundantReturn
Clone this wiki locally