WooKoo Blog

물과 같이

개발/개발

Swift Lint 적용 룰

WooKoo 2022. 4. 11. 21:53

기본 Default 룰을 적용하면 엄청 워닝이 많이 뜨길래 필요한 디폴트 룰만 지킬려고 만들었다.

 

디폴트 룰을 전부 Disable 시킨 뒤 필요한 것만 주석처리해서 활성화 시켜주도록 하자!!

 

디폴트 룰 참고는 https://realm.github.io/SwiftLint/rule-directory.html

 

Rule Directory Reference

 

realm.github.io

레퍼런스 참고해서 필요한 것만 활성화!

 

 

.swiftlint.yml 파일에 넣어주세용

disabled_rules:
- line_length
- closing_brace
- closure_parameter_position
- colon
- comma
- comment_spacing
- compiler_protocol_init
- computed_accessors_order
- control_statement
- custom_rules
- cyclomatic_complexity
- deployment_target
- discouraged_direct_init
- duplicate_enum_cases
- duplicate_imports
- duplicated_key_in_dictionary_literal
- dynamic_inline
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- file_length
- for_where
- force_cast
- force_try
- function_body_length
- function_parameter_count
- generic_type_name
- identifier_name
- implicit_getter
- inclusive_language
- inert_defer
- is_disjoint
- large_tuple
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_nsgeometry_functions
- legacy_random
- line_length
- mark
- multiple_closures_with_trailing_closure
- nesting
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- nsobject_prefer_isequal
- opening_brace
- operator_whitespace
- orphaned_doc_comment
- private_over_fileprivate
- private_unit_test
- protocol_property_accessors_order
- reduce_boolean
- redundant_discardable_let
- redundant_objc_attribute
- redundant_optional_initialization
- redundant_set_access_control
- redundant_string_enum_value
- redundant_void_return
- return_arrow_whitespace
- self_in_property_initialization
- shorthand_operator
- statement_position
- superfluous_disable_command
- switch_case_alignment
- syntactic_sugar
- todo
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- type_body_length
- type_name
- unneeded_break_in_switch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
- unused_optional_binding
- unused_setter_value
- valid_ibinspectable
- vertical_parameter_alignment
- vertical_whitespace
- void_return
- xctfail_message

included:
  - HomeViewController.swift
  
excluded: # 린트 과정에서 무시할 파일 경로. `included`보다 우선순위 높음
  - Pods
  - SignUp/AppDelegate.swift
  - SignUp/SceneDelegate.swift

#
#### warning으로 처리할 지 error로 처리할 지 그 레벨을 설정할 수 있습니다.
#force_cast: warning # implicitly
#force_try:
#  severity: warning # explicitly

 

Swift lint Run Script는

if which "${PODS_ROOT}/SwiftLint/swiftlint" >/dev/null; then
    ${PODS_ROOT}/SwiftLint/swiftlint
else
    echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi