π₯μ μ¬ μ μλ νλ‘μ νΈλ₯Ό ν λ, νμ SwiftLintλ₯Ό μ μ©νλ©° κ°λ°νμλ€.
μ μ¬ ν, νμ¬ νλ‘μ νΈμμλ λ¦°νΈκ° μ μ©λμ΄ μμ§ μμκ³ , κ·Έ νμμ±μ λκ»΄ λ¦°νΈ μ μ©μ μ μνλ€. μμ±λμ΄ μλ μ½λλ€μμ μλ§μ μλ¬κ° λ¬κ³ , λ€μ λ²κ±°λ‘μ΄ μμ λ€λ μμμ§λ§, 무μμμ μΌλ‘ μμ±νλ μ½λκ° κΆμ₯λλ 컨벀μ μ΄μλ€λ κ²λ μκ² λκ³ , λͺ¨λ₯΄λ 컨벀μ λ€λ μλ‘ μκ² λμ΄ μλ―Έ μμλ€κ³ μκ°νλ€.
μλμ κΈμ νλ‘μ νΈμ λ¦°νΈλ₯Ό μ μ©νλ©° μμ νλ κ³Όμ μ λν κΈ°λ‘μ΄λ€.π©π»
2020λ 8μ 14μΌ κΈμμΌ (warning: 999+, error: 999+)λ‘ μμ
SwiftLint μ΅μ΄ μ μ©μ μ½ 11826κ°μ μλ¬λ‘ μμν¨π± (999+/999+)
[ 2020.8.14 ]
μ μΈν κ·μΉκ³Ό νμΌλ€μ μΆκ°νλ©΄μ μ΄ 3702κ°κ° λ¨ (999+/105)
[ 2020.8.14 ]
// .swiftlint.yml
disabled_rules:
- leading_whitespace
- trailing_whitespace
excluded:
- νμΌ μμΉ/AppDelegate.swift
- Pods
line_length μ μΈ μΆκ° μ΄ 3473κ° (999+/89)
[ 2020.8.14 ]
μ λ°μ μΌλ‘ κΈΈκ² μμ±λ μ½λλ€μ΄ λ§μκ³ , μ°μ μ μΈνλ€.
// .swiftlint.yml
disabled_rules:
- line_length
Libaries μ μΈ μ΄ 2553κ° (999+/78)
[ 2020.8.14 ]
μΈλΆ λΌμ΄λΈλ¬λ¦¬ νμΌλ μΆκ°λ‘ μ μΈνλ€.
// swiftlint.yml
excluded:
- Libraries
2020λ 8μ 18μΌ νμμΌ (warning: 999+, error:78) λ‘ μμπΉ
Force Cast Violation: Force casts should be avoided. (force_cast)
[ 24κ° - 2020.8.18 ]
κ°μ μΊμ€ν νλ λΆλΆμ΄ μλλ‘ μμ νμλ€. μλλ κ·Έ μ€ λνμ μΈ 2κ°μ§ μμλ€.
Dictionary extention μμ
[ 4κ° - 2020.8.18 ]
λμ λ리μ ν€κ°μ μλ¬Έμλ λλ¬Έμλ‘ λ°κΎΈλ ν¨μκ° extensionμ μ μλμ΄ μμλλ°, κ°μ μΊμ€ν μ νλ λ°©μμ΄μλ€.
μλμ μΆμ²λ₯Ό ν΅ν΄ κ°μ μΊμ€ν μ΄ μλλ‘ μμ νμλ€.
// λ³κ²½ μ
extension Dictionary where Key: ExpressibleByStringLiteral {
mutating func lowercaseKeys() {
for key in self.keys {
let str = (key as! String).lowercased()
self[str as! Key] = self.removeValue(forKey: key)
}
}
mutating func uppercaseKeys() {
for key in self.keys {
let str = (key as! String).uppercased()
self[str as! Key] = self.removeValue(forKey: key)
}
}
}
// λ³κ²½ ν
extension Dictionary where Key: StringProtocol {
mutating func setAllKeysLowercase() {
for key in self.keys {
if let lowercaseKey = key.lowercased() as? Key {
self[lowercaseKey] = self.removeValue(forKey: key)
}
}
}
mutating func setAllKeysUppercase() {
for key in self.keys {
if let uppercaseKey = key.uppercased() as? Key {
self[uppercaseKey] = self.removeValue(forKey: key)
}
}
}
}
// μΆμ²: https://stackoverflow.com/questions/33180028/extend-dictionary-where-key-is-of-type-string
UserDefaults value as! Int κ°μ μΊμ€ν
[ 2κ° - 2020.8.18 ]
`Int`κ°μ κ°κ³ μλ UserDefaultsλ κ°μ μΊμ€ν νμ§ μκ³ `func integer(forKey defaultName: String) -> Int`λ₯Ό μ¬μ©νλ©΄ λλ€.
// λ³κ²½ μ
return FontSize(rawValue: UserDefaults.standard.value(forKey: "ν€κ°") as! Int)
// λ³κ²½ ν
return FontSize(rawValue: UserDefaults.standard.integer(forKey: "ν€κ°"))
Type Name Violation: Type name should only contain alphanumeric characters: 'LINE_POSITION' (type_name)
Identifier Name Violation: Enum element name should only contain alphanumeric characters: 'LINE_POSITION_TOP' (identifier_name)
[ 8κ° - 2020.8.18 ]
μ€μννΈμμλ μΉ΄λ©μΌμ΄μ€π«κ° κΈ°λ³Έ λͺ λͺ λ²μΌλ‘ μ¬μ©νκ³ μλ€. λν Enum νμ λͺ μ λλ¬Έμλ‘ μμνκ³ , caseλ μλ¬Έμλ‘ μμνλ€.
// λ³κ²½ μ
enum LINE_POSITION {
case LINE_POSITION_TOP
case LINE_POSITION_BOTTOM
}
// λ³κ²½ ν
enum LinePosition {
case top
case bottom
}
Force Try Violation: Force tries should be avoided. (force_try)
[3κ° - 2020.8.18 ]
try! ꡬ문μ μ¬μ©νλλ° μλ¬κ° λ°μνλ©΄ λ°νμ μλ¬λ₯Ό λ°μμν€κ³ , μ±μ΄ κ°μ μ’ λ£λλ―λ‘ try? κ΅¬λ¬Έμ΄ κΆμ₯λλ€.
// λ³κ²½ μ
let realm = try! Realm()
// λ³κ²½ ν
let realm = try? Realm()
Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator) 2889 (999+, 9)
[ 1κ° - 2020.8.18 ]
μ°μ°μ ν λ, νλ‘νΌν°λ₯Ό λ°λ³΅μ μΌλ‘ λͺ μνλ κ²λ³΄λ€ μΆμ½λ μ°μ° ννμ μ°λ κ²μ κΆμ₯νλ€.
// λ³κ²½ μ
naviHeight = naviHeight + top
// λ³κ²½ ν
naviHeight += top
Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace) 2946 (999+, 9)
[ 100μ¬κ° - 2020.8.18 ]
μ½λ μ¬μ΄μ ν μ€μ©λ§ λλλ‘ μμ νλ€.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
[ 900μ¬κ° - 2020.8.18 ]
μ€μννΈμμλ νμ μ μ(let a: Int?)λ λμ λ리μμ(Dictionary[key: _, value: _]) μ½λ‘ `:`μ μ¬μ©ν λ, μμ λΆμ΄κ³ λ€λ ν μΉΈ μ€νμ΄μ€λ₯Ό λ£λ κ² μΌλ°μ μ΄λ€. λ§μ λΆλΆμ΄ κ·Έλ μ§ μμ, λͺ¨λ μμ μ νμλ€.
// λ³κ²½ μ
var localized:String {}
// λ³κ²½ ν
var localized: String {}
Trailing Semicolon Violation: Lines should not have trailing semicolons. (trailing_semicolon) (999+, 9)
[ 4κ° - 2020.8.18 ]
μ½λ λμ μΈλ―Έμ½λ‘ `;`μ΄ λΆμ΄ μλ κ²½μ°κ° μμλ€. μ€μννΈμμλ μΈλ―Έμ½λ‘ μ μ¬μ©νμ§ μλ κ²μ΄ μΌλ°μ μ΄λ―λ‘ μμ νλ€.
Unneeded Break in Switch Violation: Avoid using unneeded break statements. (unneeded_break_in_switch) (999+, 9)
[ 10κ° - 2020.8.18 ]
μ€μννΈμ Switch λ¬Έμ caseλ₯Ό λ§μ‘±μν¨ νμ λ€μ caseλ‘ fall throughλ₯Ό νμ§ μμ, breakλ¬Έμ΄ νμμλ€. caseμ λν λμμ΄ μ무κ²λ μμ λλ§ μ¬μ©νλ©΄ λκΈ° λλ¬Έμ λΆνμν breakλ¬Έμ μ κ±°νλ€.
Unneeded NotificationCenter Removal Violation: Observers are automatically unregistered on dealloc (iOS 9 / macOS 10.11) so you should't call removeObserver(self) in the deinit. (unneeded_notification_center_removal)
[ 4κ° - 2020.8.18 ]
(μ€μννΈλ λ μ΄μ νμνμ§ μμ μΈμ€ν΄μ€λ₯Ό μλμΌλ‘ ν λΉ ν΄μ νμ¬ λ¦¬μμ€λ₯Ό ν보νλ€. Swiftλ μλ μ°Έμ‘° κ³μ°(ARC)μ ν΅ν΄ μΈμ€ν΄μ€μ λ©λͺ¨λ¦¬ κ΄λ¦¬λ₯Ό μ²λ¦¬νλ€. μΌλ°μ μΌλ‘ μΈμ€ν΄μ€ ν λΉμ΄ ν΄μ λ λ μλμΌλ‘ μ 리ν νμκ° μλ€.)
OS X 10.11μ iOS 9.0λΆν° NSNotificationCenter λ° NSDistributedNotificationCenterλ λ μ΄μ ν λΉμ΄ ν΄μ λλ €λ λ±λ‘λ μ΅μ λ²μκ² μλ¦Όμ 보λ΄μ§ μλλ€. λ°λΌμ, μ΅μ λ²κ° ν λΉ ν΄μ λ°©λ²μΌλ‘ λ±λ‘μ μ·¨μν νμκ° μλ€.
-[NSNotificationCenter addObserverForName : object : queue : usingBlock] λ©μλλ₯Ό ν΅ν λΈλ‘ κΈ°λ° μ΅μ λ²λ μμ€ν μ΄ μ¬μ ν μ΄λ¬ν μ΅μ λ²μ λν κ°λ ₯ν μ°Έμ‘°λ₯Ό 보μ νλ―λ‘ λ μ΄μ μ¬μ©νμ§ μμ λλ λ±λ‘μ ν΄μ ν΄μΌ νλ€. λ§μ½ μ λλ‘ μ κ±°ν΄ μ£Όμ§ μμΌλ©΄ μ΅μ λ²κ° μμλ κ°μ²΄κ° ν΄μ λμμ λ, Notification μ΄ μ λ¬λλ©΄ μ±μ΄ μ£½λλ€.
λ°λΌμ, deinitμμ removeObserver(self)λ₯Ό νΈμΆνμ§ μμλ λλ―λ‘ μμ νμλ€.
Unused Closure Parameter Violation: Unused parameter "timer" in a closure should be replaced with _. (unused_closure_parameter)
[ 54κ° - 2020.8.18 ]
μ¬μ©νμ§ μλ ν΄λ‘μ νλΌλ―Έν°λ€μ `_` μμΌλμΉ΄λ μλ³μλ‘ λ³κ²½νμλ€.
// λ³κ²½ μ
webRTCClient?.set(remoteSdp: description, completion: { (error) in
// λ³κ²½ ν
webRTCClient?.set(remoteSdp: description, completion: { _ in
2020λ 8μ 19μΌ μμμΌ (warning: 741, error:9)λ‘ μμπ€―
Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration. (opening_brace) (741, 9)
[ 1076κ° - 2020.8.19 ]
ν¨μ λ±μμ μμ λκ΄νΈ`{`λ₯Ό μ΄ λ, μ μͺ½μ κ³΅λ°±μ΄ ν μΉΈ λ€μ΄κ°μΌ νλλ°, λΆμ΄ μλ κ²λ€μ λͺ¨λ μμ νλ€.
// λ³κ²½ μ
func setTableView(){}
// λ³κ²½ ν
func setTableView() {}
λν, λΆνμν μ£Όμκ³Ό iOS λ²μ λ³ λΆκΈ° μ²λ¦¬ λΆλΆμ μμ νλ€. κ°λ° μ΄λ°μλ iOS 10λΆν° μ§μνλ €κ³ νμΌλ, κ°λ° κ³Όμ μμ iOS 11λ‘ λ³κ²½λμλ€. iOS 10μ μν λΆκΈ° μ²λ¦¬κ° λ¨μμμ΄, μ΄λ₯Ό μμ νμλ€.
2020λ 8μ 20μΌ λͺ©μμΌ (warning: 767, error: 8)λ‘ μμπ£
Switch and Case Statement Alignment Violation: Case statements should vertically align with their enclosing switch statement. (switch_case_alignment) (767, 8)
[ 10κ° - 2020.8.20 ]
μ€μννΈμ Switchλ¬Έμ Case ꡬ문과 μμͺ½μ΄ λμΌνκ² μ λ ¬μ΄ λμ΄μΌ νλλ° κ·Έλ μ§ μμ λΆλΆμ΄ μμ΄ μμ νλ€.
// λ³κ²½ μ
switch something {
case .A:
...
case .B:
...
default:
...
// λ³κ²½ ν
switch something {
case .A:
...
case .B:
...
default:
...
Control Statement Violation: if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses. (control_statement) (757, 8)
[ 2κ° - 2020.8.20 ]
μ€μννΈμμλ if ꡬ문 λ±μ 쑰건 λΆλΆμ μκ΄νΈλ‘ λ¬Άμ§ μμλ λλ€.
// λ³κ²½ μ
if(widthRatio > heightRatio) {}
// λ³κ²½ ν
if widthRatio > heightRatio {}
Comma Spacing Violation: There should be no space before and one after any comma. (comma)
[ 26κ° - 2020.8.20 ]
μ½€λ§`,`λ₯Ό μ¬μ©ν κ²½μ°, κ·Έ μμ λΆκ³ κ·Έ λ€λ ν μΉΈμ© κ³΅λ°±μ΄ λ€μ΄κ°μΌ νλλ° κ·Έλ μ§ μμ κ²½μ°λ€μ΄ μμ΄μ μμ νλ€.
Statement Position Violation: Else and catch should be on the same line, one space after the previous declaration. (statement_position)
[ 297κ° - 2020.8.20 ]
else κ΅¬λ¬Έμ΄ μ΄μ κ΄νΈμ λμΌν μ€μ νμνλ κ²μ κΆμ₯νλ€.
// λ³κ²½ μ
if {
}
else {
}
// λ³κ²½ ν
if {
} else {
}
Mark Violation: MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...' (mark) (445, 8)
[ 4κ° - 2020.8.20 ]
Mark μ£Όμμ ννλ `// MARK:` λ `// MARK: -`λ₯Ό μ¬μ©ν΄μΌ νλ€.
Returning Whitespace Violation: Return arrow and return type should be separated by a single space or on a separate line. (return_arrow_whitespace) (441, 8)
[ 42κ° - 2020.8.20 ]
λ°ν νμ μ μλ €μ£Όλ νμ΄ν`->`μ λ°ν νμ μ¬μ΄μ κ³΅λ°±μ΄ ν μΉΈμ© νμνλ° λΆμ΄ μλ κ²½μ°λ€μ΄ μμλ€.
// λ³κ²½ μ
func ν¨μ()->λ°ννμ
{}
// λ³κ²½ ν
func ν¨μ() -> λ°ννμ
{}
Weak Delegate Violation: Delegates should be weak to avoid reference cycles. (weak_delegate)
[ 5κ° - 2020.8.20 ]
delegate νλ‘νΌν°λ μν μ°Έμ‘°λ₯Ό λ§κΈ° μν΄ weak μ°Έμ‘°λ₯Ό ν΄μΌ νλ€.
// λ³κ²½ μ
var delegate: ν΄λμ€Delegate?
// λ³κ²½ ν
weak var delegate: ν΄λμ€Delegate?
Class Delegate Protocol Violation: Delegate protocols should be class-only so they can be weakly referenced. (class_delegate_protocol)
[ 2κ° - 2020.8.20 ]
delegate νλ‘ν μ½μ μ½ν μ°Έμ‘°λ₯Ό ν μ μλλ‘ class μ μ©μ΄ λμ΄μΌ νλ€.
// λ³κ²½ μ
protocol ν΄λμ€Delegate {
...
}
// λ³κ²½ ν
protocol ν΄λμ€Delegate: class {
...
}
Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
[ 8κ° - 2020.8.20 ]
νμΌμ λμ λΉ μ€μ΄ μ¬λ¬ μ€μΈ κ²½μ°κ° μμλ€. νμΌμ λμ λΉ μ€μ ν μ€λ§ λ€μ΄κ°λ κ²μ κΆμ₯νλ€.
No Space in Method Call Violation: Don't add a space between the method name and the parentheses. (no_space_in_method_call) (378, 8)
[ 6κ° - 2020.8.20 ]
λ©μλ νΈμΆ μμ λ©μλμ κ΄νΈ μ¬μ΄μ κ³΅λ°±μ΄ λ€μ΄κ°λ κ²½μ°κ° μμλ€. λΆμ΄λ κ²μ κΆμ₯νκ³ μλ€.
Syntactic Sugar Violation: Shorthand syntactic sugar should be used, i.e. [String: Int] instead of Dictionary<String, Int>. (syntactic_sugar)
[ 102κ° - 2020.8.20 ]
Dictionary νμ μ μ¬μ©ν λ, `Dictionary<Key, Value>` λ³΄λ€ `[Key: Value]`λ‘ λͺ μνλ κ²μ κΆμ₯νλ€.
// λ³κ²½ μ
var νλΌλ―Έν° = Dictionary<String, Int>()
// λ³κ²½ ν
var νλΌλ―Έν° = [String: Int]()
Syntactic Sugar Violation: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. (syntactic_sugar)
[ 32κ° - 2020.8.20 ]
Array νμ μ μ¬μ©ν λ, `Array<Element>` λ³΄λ€ `[Element]`λ‘ λͺ μνλ κ²μ κΆμ₯νλ€.
// λ³κ²½ μ
var νλΌλ―Έν° = Array<String>()
// λ³κ²½ ν
var νλΌλ―Έν° = [String]()
Void Return Violation: Prefer -> Void over -> (). (void_return)
[ 1κ° - 2020.8.20 ]
Void νμ μ λ°ννλ κ²½μ°, λΉ κ΄νΈ `()`λ₯Ό μ°λ κ²λ³΄λ€ `Void`λ₯Ό λͺ μνλ κ²μ κΆμ₯νλ€.
// λ³κ²½ μ
func ν¨μ(completion: @escaping () -> ()) {}
// λ³κ²½ ν
func ν¨μ(completion: @escaping () -> Void) {}
Computed Accessors Order Violation: Computed properties should declare first the getter and then the setter. (computed_accessors_order)
[ 17κ° - 2020.8.20 ]
μ°μ° νλ‘νΌν°μ `get`κ³Ό `set`μ μμκ° `get`μ΄ λ¨Όμ λμμΌ νλ€.
Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)
[ 1κ° - 2020.8.20 ]
`set`μ νμ§ μλ μ½κΈ° μ μ© μ°μ° νλ‘νΌν°μ κ²½μ° `get` ν€μλλ₯Ό μ¬μ©νμ§ μμλ λλ€.
Vertical Parameter Alignment Violation: Function parameters should be aligned vertically if they're in multiple lines in a declaration. (vertical_parameter_alignment)
[ 4κ° - 2020.8.20 ]
ν¨μ νλΌλ―Έν°λ€μ΄ λ°λ‘ ν μ€μ© μμ±λμ΄ μμλλ°, κ·Έ νλΌλ―Έν°λ€μ΄ μ λ ¬λμ§ μμ κ²½μ°κ° μμλ€.
2020λ 8μ 21μΌ κΈμμΌ (warning: 244, error: 8)λ‘ μμπ€
For Where Violation: where clauses are preferred over a single if inside a for. (for_where)
[ 8κ° - 2020.8.21 ]
for λ¬Έ μμμ if λ¬ΈμΌλ‘ 쑰건 νμΈμ νλ κ²½μ°, κ·Έλ³΄λ€ forλ¬Έμ where μ μ¬μ©μ κΆμ₯νλ€.
// λ³κ²½ μ
for index in 3..<array.count {
if index % 2 == 1 {
...
}
}
// λ³κ²½ ν
for index in 3..<array.count where index % 2 == 1 {
...
}
Immutable value 'str' was never used; consider replacing with '_' or removing it
[ 2κ° - 2020.8.21 ]
μ¬μ©νμ§ μλ μμκ° μμΌλ©΄ μμΌλμΉ΄λ μλ³μ `_`λ‘ λ체νκ±°λ μμ νλ€.
Empty Enum Arguments Violation: Arguments can be omitted when matching enums with associated types if they are not used. (empty_enum_arguments)
[ 2κ° - 2020.8.21 ]
Switchλ¬Έμμ enumμ μ¬μ©ν λ, enumμ μ°κ΄ κ°μ μ¬μ©νμ§ μλλ€λ©΄ μμ ν΄λ λλ€.
// Ex)
enum Barcode {
case upc(Int, Int, Int, Int)
case qrCode(String)
}
var productBarcode = Barcode.upc(8, 85909, 51226, 3)
// λ³κ²½ μ
switch productBarcode {
case .upc(_,_,_,_):
print("UPC: \(productBarcode.self)")
case .qrCode(let productCode):
print("QR code: \(productCode).")
}
// λ³κ²½ ν
switch productBarcode {
case .upc:
print("UPC: \(productBarcode.self)")
case .qrCode(let productCode):
print("QR code: \(productCode).")
}
Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
[ 12κ° - 2020.8.21 ]
ν΄λ‘μ κ° μ¬λ¬ κ° μλ ν¨μμ κ²½μ°, λ§μ§λ§ ν΄λ‘μ νλΌλ―Έν°λ₯Ό μΆμ½νμ§ μλ κ²μ λ κΆμ₯νλ€.
// λ³κ²½ μ
UIView.animate(withDuration: 0.2,
animations: {},
}) { _ in
self.removeFromSuperview()
}
// λ³κ²½ ν
UIView.animate(withDuration: 0.2,
animations: {},
competion: { _ in
self.removeFromSuperview()
})
Legacy Constructor Violation: Swift constructors are preferred over legacy convenience functions. (legacy_constructor)
[ 6κ° - 2020.8.21 ]
μ€μννΈμμλ μ€λλ C ν¨μλ³΄λ€ β¨μλ‘μ΄ sturct initializerλ₯Ό μ¬μ©νκΈ°λ₯Ό κΆμ₯νκ³ μλ€.
// λ³κ²½ μ
NSMakeRange(0, length)
// λ³κ²½ ν
NSRange(location: 0, length: length)
Closure Parameter Position Violation: Closure parameters should be on the same line as opening brace. (closure_parameter_position)
[ 13κ° - 2020.8.21 ]
ν΄λ‘μ μ νλΌλ―Έν°κ° λ€μ μ€λ‘ λμ΄κ° μλ κ²½μ°κ° μμλλ°, νλΌλ―Έν°λ€μ΄ ν΄λ‘μ μ κ΄νΈμ κ°μ μ€μ μμΉν΄μΌ νλ€λ κ²μ΄λ€.
Redundant Discardable Let Violation: Prefer _ = foo() over let _ = foo() when discarding a result from a function. (redundant_discardable_let)
[ 12κ° - 2020.8.21 ]
ν¨μμ λ°ν κ°μ μ¬μ©νμ§ μμ λ, `let _ = ν¨μ()`λ³΄λ€ κ·Έλ₯ `_ = ν¨μ()` λ‘ μ¬μ©νλ κ²μ΄ λ μ’λ€.
μλλ©΄ ν¨μλ₯Ό μ μν λ @discardableResultλ₯Ό λΆμ¬μ£Όλ©΄ λ°ν κ°μ΄ μ¬μ©λμ§ μλλΌλ μλ¬κ° λ¨μ§ μκ² ν μ μλ€.
// λ³κ²½ μ
let _ = ν¨μλͺ
()
// λ³κ²½ ν
_ = ν¨μλͺ
()
OR
@discardableResult
func ν¨μλͺ
() -> λ°νκ° {
}
Unused Optional Binding Violation: Prefer != nil over let _ = (unused_optional_binding)
[ 2κ° - 2020.8.21 ]
μ¬μ©νμ§ μλ μ΅μ λ λ°μΈλ©μ nilμ΄ μλ κ²μ νμΈνλ λ°©μμ΄ λ μ’λ€.
// λ³κ²½ μ
if let _ = λ³μ {}
// λ³κ²½ ν
if λ³μ != nil {}
Redundant Optional Initialization Violation: Initializing an optional variable with nil is redundant. (redundant_optional_initialization)
[ 1κ° - 2020.8.21 ]
μ΅μ λ λ³μλΌλ©΄ μ΅μ΄μ μλμΌλ‘ nilλ‘ μ΄κΈ°νκ° λκΈ° λλ¬Έμ λͺ μν΄μ£Όμ§ μμλ λλ€.
// λ³κ²½ μ
var λ³μλͺ
: String? = nil
// λ³κ²½ ν
var λ³μλͺ
: String?
Redundant String Enum Value Violation: String enum values can be omitted when they are equal to the enumcase name. (redundant_string_enum_value)
[ 19κ° - 2020.8.21 ]
String νμ μ Enumμμ λμΌν κ°μ΄λΌλ©΄ μ€λ³΅μΌλ‘ μ°μ§ μμλ μ¬μ©ν μ μμ΄ μμ νμλ€.
// λ³κ²½ μ
enum CallType: String {
case video = "video"
case voice = "voice"
}
// λ³κ²½ ν
enum CallType: String {
case video
case voice
}
Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'vc' (identifier_name)
[ 60κ° => 28κ° - 2020.8.21 ]
ViewController λ³μκ° 'vc'λ‘ λλΆλΆ μμ±λμ΄ μμλλ°, μ’ λ λͺ ννκ² νΉμ 컨νΈλ‘€λ¬ λ³μλͺ μΌλ‘ λ³κ²½νμ¬ μ΄λ€ 뷰컨νΈλ‘€λ¬μΈμ§ μ μ μλλ‘ μμ νλ€.
Expression implicitly coerced from 'Date?' to 'Any'
[ 2κ° - 2020.8.21 ]
μμμ μΌλ‘ Any νμ μΌλ‘ κ°μ λ Date? νμ μ String νμ μΌλ‘ λ°κΏμ£Όμλ€.
// λ³κ²½ μ
print("date: ", Date νμ
λ³μ)
// λ³κ²½ ν
print("date: \(String(describing: Date νμ
λ³μ))")
File Line Length Violation: File should contain 400 lines or less: currently contains 401 (file_length)
[ 9κ° - 2020.8.21 ]
- 400μ€ μ΄νλ‘ ν° μμ μμ΄ κ°λ¨ν μ€μΌ μ μλ 2κ°μ νμΌλ§ μμ νλ€.
Orphaned Doc Comment Violation: A doc comment should be attached to a declaration. (orphaned_doc_comment)
[ 40κ° => 29κ° 2020.8.21 ]
- λ¬Έμ μ£Όμμ΄ μλλ° '/' κΈ°νΈλ₯Ό 3κ° μ΄μ μ°λ κ³³μ΄ μμλ€. νμν λΆλΆμ μ μΈν 3κ³³λ§ μμ νλ€.
Comment Spacing Violation: Prefer at least one space after slashes for comments. (comment_spacing)
- μ£Όμ // λ€μμ κ³΅λ°±μ΄ μμ΄μΌ ν¨.
Trailing Comma Violation: Collection literals should not have tailing commas. (trailing_comma)
[ 1κ°]
- 컬λ μ μμ λ§μ§λ§ κ° λ€μ μ½λ‘ μ΄ λΆμ κ²½μ°κ° μμ΄ μμ νλ€.
Closing Brace Spacing Violation: Closing brace with closing parenthesis should not have any whitespaces in the middle.(closing_brace)
[ 1κ°]
- λ«νλ μκ΄νΈ μμ μλ λ«νλ λκ΄νΈ μ¬μ΄μ κ³΅λ°±μ΄ μμ΄ μμ νλ€.
μ΅μ’ μ μΌλ‘ swiftlint.yml κ·μΉ μμ
[ 2020.8.24 ]
μ΄λ―Έ μμ±λμ΄ μλ μ½λμ μμ μ΄ ν¬κ² νμν κ² κ°μ function, file λ±μ length, parameter count λ±μ κ·μΉμ μ λΆλ€ μμ νμ§ λͺ»νκ³ μ μΈλ₯Ό νμλ€. μ°¨μ°¨ 리ν©ν λ§μ΄ λλ©΄ μ’μ κ² κ°λ€.π lengthμ λν 쑰건λ 맀μ°(?) λλν μ£Όμλλ°.. μ μ°¨ μ½λ κ°μ μ ν μ μκΈΈ κΈ°λνλ€. π
disabled_rules:
- leading_whitespace
- trailing_whitespace
- line_length
- cyclomatic_complexity
- function_body_length
- function_parameter_count
- orphaned_doc_comment
opt_in_rules:
type_body_length:
- 1000
- 1500
file_length:
warning: 3000
error: 4000
type_name:
min_length:
warning: 1
max_length:
warning: 80
error: 100
identifier_name:
min_length:
warning: 1
excluded:
- νμΌ μμΉ/AppDelegate.swift
- Pods
- Libraries