-
Notifications
You must be signed in to change notification settings - Fork 4
/
.swiftlint.yml
856 lines (663 loc) · 16.9 KB
/
.swiftlint.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
whitelist_rules:
- class_delegate_protocol
# Delegate protocols should be class-only so they can be weakly referenced.
#
# ↓protocol FooDelegate {}
#
# ↓protocol FooDelegate: Bar {}
- closing_brace
# Closing brace with closing parenthesis should not have any whitespaces in the middle.
#
# [].map({ ↓} )
- closure_end_indentation
# Closure end should have the same indentation as the line that started it.
#
# SignalProducer(values: [1, 2, 3])
# .startWithNext { number in
# print(number)
# ↓}
#
# return match(pattern: pattern, with: [.comment]).flatMap { range in
# return Command(string: contents, range: range)
# ↓}.flatMap { command in
# return command.expand()
# ↓}
- closure_parameter_position
# Closure parameters should be on the same line as opening brace.
#
# [1, 2].map {
# ↓number in
# number + 1
# }
#
# [1, 2].map {
# ↓number -> Int in
# number + 1
# }
- closure_spacing
# Closure expressions should have a single space inside each brace.
#
# [].filter(↓{$0.contains(location)})
#
# [].map(↓{$0})
- colon
# Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.
#
# let ↓abc:Void
#
# let ↓abc: Void
#
# let ↓abc :Void
#
# let ↓abc : Void
#
# let ↓abc : [Void: Void]
#
# func abc(↓def:Void) {}
#
# func abc(def: Void, ↓ghi :Void) {}
#
# let abc = [Void↓ : Void]()
#
# let abc = [Void↓: Void]()
#
# let abc = [1: [3↓ : 2], 3: 4]
- comma
# There should be no space before and one after any comma.
#
# func abc(a: String↓ ,b: String) { }
#
# func abc(a: String↓ ,b: String↓ ,c: String↓ ,d: String) { }
#
# enum a { case a↓ ,b }
#
# let result = plus(
# first: 3↓ , // #683
# second: 4
# )
- compiler_protocol_init
# The initializers declared in compiler protocols such as `ExpressibleByArrayLiteral` shouldn't be called directly.
#
# let set = ↓Set(arrayLiteral: 1, 2)
#
# let set = ↓Set.init(arrayLiteral: 1, 2)
- control_statement
# if, for, while, do, guard, switch statements shouldn't wrap their conditionals in parentheses.
#
# do { ; } ↓while (condition) {
#
# ↓switch (foo) {
#
# do { ; } ↓while(condition) {
#
# } ↓while(condition) {
#
# ↓guard (condition) else {
#
# ↓for(item in collection) {
#
# ↓if ((min...max).contains(value)) {
#
# ↓if ((a || b) && (c || d)) {
- cyclomatic_complexity
# Complexity of function bodies should be limited.
#
# ↓func f1() {
# if true {
# if true {
# if false {}
# }
# }
# if false {}
# let i = 0
# switch i {
# case 1: break
# case 2: break
# case 3: break
# case 4: break
# default: break
# }
# for _ in 1...5 {
# guard true else {
# return
# }
# }
# }
- discarded_notification_center_observer
# When registing for a notification using a block, the
# opaque observer that is returned should be stored so it
# can be removed later.
#
# ↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { }
#
# ↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { })
- dynamic_inline
# Avoid using 'dynamic' and '@inline(__always)' together.
#
# class C {
# @inline(__always) dynamic ↓func f() {}
# }
#
# class C {
# @inline(__always) public dynamic ↓func f() {}
# }
#
# class C {
# @inline(__always) dynamic internal ↓func f() {}
# }
#
# class C {
# @inline(__always)
# dynamic ↓func f() {}
# }
#
# class C {
# @inline(__always)
# dynamic
# ↓func f() {}
# }
- empty_count
# Prefer checking `isEmpty` over comparing `count` to zero.
#
# [Int]().↓count == 0
#
# [Int]().↓count > 0
#
# [Int]().↓count != 0
- empty_parameters
# Prefer `() -> ` over `Void -> `.
#
# let abc: ↓Void -> Void = {}
#
# func foo(completion: ↓Void -> Void)
#
# func foo(completion: ↓Void throws -> Void)
#
# let foo: ↓Void -> () throws -> Void)
- empty_parentheses_with_trailing_closure
# When using trailing closures, empty parentheses should be
# avoided after the method call.
#
# [1, 2].map↓() { $0 + 1 }
#
# [1, 2].map↓( ) { $0 + 1 }
#
# [1, 2].map↓() { number in
# number + 1
# }
#
# [1, 2].map↓( ) { number in
# number + 1
# }
- explicit_init
# Explicitly calling .init() should be avoided.
#
# [1].flatMap{String↓.init($0)}
#
# [String.self].map { Type in Type↓.init(1) }
- fatal_error_message
# A fatalError call should have a message.
#
# func foo() {
# ↓fatalError("")
# }
#
# func foo() {
# ↓fatalError()
# }
# - file_length
# Files should not span too many lines.
- first_where
# Prefer using `.first(where:)` over `.filter { }.first` in collections.
#
# ↓myList.filter { $0 % 2 == 0 }.first
#
# ↓myList.filter({ $0 % 2 == 0 }).first
#
# ↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first
#
# ↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first?.something()
#
# ↓myList.filter(someFunction).first
#
# ↓myList.filter({ $0 % 2 == 0 })
# .first
- for_where
# `where` clauses are preferred over a single `if` inside a `for`.
#
# for user in users {
# ↓if user.id == 1 { return true }
# }
- force_cast
# Force casts should be avoided.
#
# NSNumber() ↓as! Int
- force_try
# Force tries should be avoided.
#
# func a() throws {}; ↓try! a()
- force_unwrapping
# Force unwrapping should be avoided.
#
# let url = NSURL(string: query)↓!
#
# navigationController↓!.pushViewController(viewController, animated: true)
#
# let unwrapped = optional↓!
#
# return cell↓!
#
# let url = NSURL(string: "http://www.google.com")↓!
#
# let dict = ["Boooo": "👻"]func bla() -> String { return dict["Boooo"]↓! }
# - function_body_length
# Functions bodies should not span too many lines.
# - function_parameter_count
# Number of function parameters should be low.
#
# ↓func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
#
# ↓func initialValue(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
#
# ↓func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int = 2, g: Int) {}
#
# struct Foo {
# init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
# ↓func bar(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}
# }
- generic_type_name
# Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length.
#
# func foo<↓T_Foo>() {}
#
# func foo<↓TTTTTTTTTTTTTTTTTTTTT>() {}
#
# func foo<↓type>() {}
# - identifier_name
# Identifier names should only contain alphanumeric characters and start with a lowercase character or should only contain capital letters. In an exception to the above, variable names may start with a capital letter when they are declared static and immutable. Variable names should not be too long or too short.
#
# ↓let MyLet = 0
#
# ↓let _myLet = 0
#
# private ↓let myLet_ = 0
#
# ↓let myExtremelyVeryVeryVeryVeryVeryVeryLongLet = 0
#
# ↓let i = 0
#
# enum Foo { case ↓MyEnum }
#
# ↓func IsOperator(name: String) -> Bool
#
# private ↓let _i = 0
- implicit_getter
# Computed read-only properties should avoid using the get keyword.
#
# class Foo {
# var foo: Int {
# ↓get {
# return 20
# }
# }
# }
# - implicitly_unwrapped_optional
# Implicitly unwrapped optionals should be avoided when possible.
#
# let label: UILabel!
#
# let IBOutlet: UILabel!
#
# let labels: [UILabel!]
#
# var ints: [Int!] = [42, nil, 42]
#
# let label: IBOutlet!
- large_tuple
# Tuples shouldn't have too many members. Create a custom type instead.
#
# ↓let foo: (Int, Int, Int)
#
# func foo(↓bar: (Int, Int, Int))
#
# func foo() -> ↓(Int, Int, Int)
#
# func foo() throws -> ↓(Int, ↓(String, String, String), Int) {}
#
# func getDictionaryAndInt() -> (Dictionary<Int, ↓(String, String, String)>, Int)?
- leading_whitespace
# Files should not contain leading whitespace.
- legacy_cggeometry_functions
# Struct extension properties and methods are preferred over legacy functions
#
# ↓CGRectGetWidth(rect)
#
# ↓CGRectIsNull(rect)
#
# ↓CGRectIntersectsRect(rect1, rect2)
- legacy_constant
# Struct-scoped constants are preferred over legacy global constants.
#
# ↓CGRectInfinite
#
# ↓CGSizeZero
#
# ↓CGRectNull
#
# ↓CGFloat(M_PI)
- legacy_constructor
# Swift constructors are preferred over legacy convenience functions.
#
# ↓CGPointMake(10, 10)
#
# ↓CGSizeMake(aWidth, aHeight)
#
# ↓NSMakeRect(xVal, yVal, width, height)
#
# ↓NSEdgeInsetsMake(top, left, bottom, right)
- line_length
# Lines should not span too many characters.
- mark
# MARK comment should be in valid format.
#
# ↓//MARK: bad
#
# ↓// MARK: bad
#
# ↓// MARK: bad
#
# ↓// MARK:bad
#
# ↓// MARK: -bad
#
# ↓//MARK: - bad
#
# ↓//MARK:- bad
- missing_docs
# Public declarations should be documented.
#
# ↓public func a() {}
#
# ↓// regular comment
# public func a() {}
#
# ↓/* regular comment */
# public func a() {}
#
# /// docs
# public protocol A {
# ↓// no docs
# var b: Int { get } }
# /// docs
# public struct C: A {
#
# ↓public let b: Int
# }
- nesting
# Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep.
#
# class A { class B { ↓class C {} } }
#
# struct A { struct B { ↓struct C {} } }
#
# enum A { enum B { ↓enum C {} } }
#
# func func0() {
# func func1() {
# func func2() {
# func func3() {
# func func4() {
# func func5() {
# ↓func func6() {
# }
# }
# }
# }
# }
# }
# }
- opening_brace
# Opening braces should be preceded by a single space and on the same line as the declaration.
#
# func abc(↓){
# }
#
# func abc()↓
# { }
#
# [].map(↓){ $0 }
#
# [].map↓( { } )
#
# if let a = b{ }
#
# while a == b{ }
#
# guard let a = b else{ }
- operator_usage_whitespace
# Operators should be surrounded by a single whitespace when they are being used.
#
# let foo = 1↓+2
#
# let foo = 1↓ + 2
#
# let foo = 1↓ + 2
#
# let foo = 1↓ + 2
#
# let foo↓=1↓+2
#
# let foo = bar↓??0
- operator_whitespace
# Operators should be surrounded by a single whitespace when defining them.
#
# ↓func <|(lhs: Int, rhs: Int) -> Int {}
#
# ↓func <|<<A>(lhs: A, rhs: A) -> A {}
#
# ↓func <| (lhs: Int, rhs: Int) -> Int {}
# - private_outlet
# IBOutlets should be private to avoid leaking UIKit to higher layers.
#
# class Foo {
# @IBOutlet ↓var label: UILabel?
# }
- redundant_discardable_let
# Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function.
#
# ↓let _ = foo()
#
# if _ = foo() { ↓let _ = bar() }
- redundant_nil_coalescing
# nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant
#
# - var myVar: Int? = nil
# myVar↓ ?? nil
- redundant_optional_initialization
# Initializing an optional variable with nil is redundant.
#
# var myVar: Int?↓ = nil
#
# var myVar: Optional<Int>↓ = nil
#
# var myVar: Int?↓=nil
#
# var myVar: Optional<Int>↓=nil
- redundant_string_enum_value
# String enum values can be omitted when they are equal to the enumcase name.
#
# enum Numbers: String {
# case one = ↓"one"
# case two = ↓"two"
# }
#
# enum Numbers: String {
# case one = ↓"one", two = ↓"two"
# }
- redundant_void_return
# Returning Void in a function declaration is redundant.
#
# func foo()↓ -> Void {}
#
# protocol Foo {
# func foo()↓ -> Void
# }
#
# func foo()↓ -> () {}
#
# protocol Foo {
# func foo()↓ -> ()
# }
- return_arrow_whitespace
# Return arrow and return type should be separated by a single space or on a separate line.
#
# func abc()↓->Int {}
#
# func abc()↓->[Int] {}
#
# func abc()↓->(Int, Int) {}
#
# func abc()↓-> Int {}
#
# func abc()↓ ->Int {}
#
# var abc = {(param: Int)↓ ->Bool in }
#
# var abc = {(param: Int)↓->Bool in }
- shorthand_operator
# Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning.
#
# ↓foo = foo - 1
#
# ↓foo = foo - aVariable
#
# ↓foo = foo - bar.method()
#
# ↓foo.aProperty = foo.aProperty - 1
- sorted_imports
# Imports should be sorted.
#
# import AAA
# import ZZZ
# import ↓BBB
# import CCC
- statement_position
# Else and catch should be on the same line, one space after the previous declaration.
#
# ↓}else if {
#
# ↓} else {
#
# ↓}
# catch {
#
# ↓}
# catch {
- syntactic_sugar
# Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>
#
# let x: ↓Array<String>
#
# let x: ↓Dictionary<Int, String>
#
# let x: ↓Optional<Int>
#
# let x: ↓ImplicitlyUnwrappedOptional<Int>
- trailing_comma
# Multi-line collection literals should have trailing commas
- trailing_newline
# Files should have a single trailing newline.
- trailing_semicolon
# Lines should not have trailing semicolons.
#
# let a = 0↓
- trailing_whitespace
# Lines should not have trailing whitespace.
- type_name
# Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length.
- unused_enumerated
# When the index or the item is not used, `.enumerated()` can be removed.
#
# for (↓_, foo) in bar.enumerated() { }
#
# for (↓_, foo) in abc.bar.enumerated() { }
#
# for (↓_, foo) in abc.something().enumerated() { }
#
# for (idx, ↓_) in bar.enumerated() { }
- unused_optional_binding
# Prefer `!= nil` over `let _ =`
#
# if let ↓_ = Foo.optionalValue { }
#
# if let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 { }
#
# if let ↓(_, _, _) = getOptionalTuple(), let bar = Foo.optionalValue { }
#
# guard let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 { }
# - valid_ibinspectable
# @IBInspectable should be applied to variables only, have its type explicit and be of a supported type
#
# @IBInspectable private ↓let count: Int
#
# @IBInspectable private ↓var count = 0
#
# @IBInspectable private ↓var count: Int?
#
# @IBInspectable private ↓var x: ImplicitlyUnwrappedOptional<Int>
- vertical_parameter_alignment
# Function parameters should be aligned vertically if they're in multiple lines in a declaration.
#
# func validateFunction(_ file: File, kind: SwiftDeclarationKind,
# ↓dictionary: [String: SourceKitRepresentable]) { }
#
# func validateFunction(_ file: File, kind: SwiftDeclarationKind,
# ↓dictionary: [String: SourceKitRepresentable]) { }
#
# func validateFunction(_ file: File,
# ↓kind: SwiftDeclarationKind,
# ↓dictionary: [String: SourceKitRepresentable]) { }
- vertical_whitespace
# Limit vertical whitespace to a single empty line.
- void_return
# Prefer `-> Void` over `-> ()`.
#
# let abc: () -> ↓() = {}
#
# func foo(completion: () -> ↓())
#
# func foo(completion: () -> ↓( ))
#
# let foo: (ConfigurationTests) -> () throws -> ↓())
# - weak_delegate
# Delegates should be weak to avoid reference cycles.
#
# ↓var delegate: SomeProtocol?
#
# ↓var scrollDelegate: ScrollDelegate?
file_length: 500
function_body_length: 40
identifier_name:
min_length: 2
max_length: 20
large_tuple: 3
line_length:
warning: 120
ignores_urls: true
# statement_position:
# statement_mode: "uncuddled_else"
trailing_comma:
mandatory_comma: true
vertical_whitespace:
max_empty_lines: 1
nesting:
type_level: 4
statement_level: 4
type_name:
max_length: 1000
cyclomatic_complexity: 11
excluded:
- Pods
- Carthage
- .idea
- vendor