This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
.swiftlint.yml
633 lines (426 loc) · 20.6 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
included:
- Demo
- Tempura
- TempuraTesting
- Project.swift
only_rules:
# Prefer using AnyObject over class for class-only protocols
# - anyobject_protocol // Already enforced by swiftformat
# Prefer using Array(seq) over seq.map { $0 } to convert a sequence into an Array
# - array_init
# Attributes should be on their own lines in functions and types, but on the same line as variables and imports
# - attributes
# Test classes must implement balanced setUp and tearDown methods.
# - balanced_xctest_lifecycle
# Prefer the new block based KVO API with keypaths when using Swift 3.2 or later
# - block_based_kvo
# Warn about listing a non-constant (var) variable in a closure's capture list. This captures the variable's value at closure creation time instead of closure call time, which may be unexpected.
- capture_variable
# Delegate protocols should be class-only so they can be weakly referenced
- class_delegate_protocol
# Closing brace with closing parenthesis should not have any whitespaces in the middle
- closing_brace
# Closure bodies should not span too many lines
# - closure_body_length
# Closure end should have the same indentation as the line that started it
# - closure_end_indentation
# Closure parameters should be on the same line as opening brace
- closure_parameter_position
# Closure expressions should have a single space inside each brace
- closure_spacing
# All elements in a collection literal should be vertically aligned
- collection_alignment
# Colons should be next to the identifier when specifying a type and next to the key in dictionary literals
- colon
# There should be no space before and one after any comma
- comma
# Prefer at least one space after slashes for comments
- comment_spacing
# The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn’t be called directly
- compiler_protocol_init
# Getter and setters in computed properties and subscripts should be in a consistent order
- computed_accessors_order
# Conditional statements should always return on the next line
# - conditional_returns_on_newline
# Prefer contains over comparing filter(where:).count to 0
- contains_over_filter_count
# Prefer contains over using filter(where:).isEmpty
- contains_over_filter_is_empty
# Prefer contains over first(where:) != nil and firstIndex(where:) != nil
- contains_over_first_not_nil
# Prefer contains over range(of:) != nil and range(of:) == nil
- contains_over_range_nil_comparison
# if, for, guard, switch, while, and catch statements shouldn’t unnecessarily wrap their conditionals or arguments in parentheses
- control_statement
# Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation
- convenience_type
# Create custom rules by providing a regex string. Optionally specify what syntax kinds to match against, the severity level, and what message to display
# - custom_rules
# Complexity of function bodies should be limited
# - cyclomatic_complexity
# Availability checks or attributes shouldn’t be using older versions that are satisfied by the deployment target
- deployment_target
# When registering for a notification using a block, the opaque observer that is returned should be stored so it can be removed later
- discarded_notification_center_observer
# Prefer assertionFailure() and/or preconditionFailure() over assert(false)
- discouraged_assert
# Discouraged direct initialization of types that can be harmful
- discouraged_direct_init
# Prefer initializers over object literals.
- discouraged_object_literal
# Prefer non-optional booleans over optional booleans.
- discouraged_optional_boolean
# Prefer empty collection over optional collection.
- discouraged_optional_collection
# Enum can’t contain multiple cases with the same name
- duplicate_enum_cases
# Imports should be unique
- duplicate_imports
# Avoid using ‘dynamic’ and ‘@inline(__always)’ together
# - dynamic_inline
# Prefer checking isEmpty over comparing collection to an empty array or dictionary literal
- empty_collection_literal
# Prefer checking isEmpty over comparing count to zero
- empty_count
# Arguments can be omitted when matching enums with associated values if they are not used
# - empty_enum_arguments
# Prefer () -> over Void ->.
- empty_parameters
# When using trailing closures, empty parentheses should be avoided after the method call
- empty_parentheses_with_trailing_closure
# Prefer checking isEmpty over comparing string to an empty string literal
- empty_string
# Empty XCTest method should be avoided
- empty_xctest_method
# Number of associated values in an enum case should be low
# - enum_case_associated_values_count
# TODOs and FIXMEs should be resolved prior to their expiry date
# - expiring_todo
# All declarations should specify Access Control Level keywords explicitly
# - explicit_acl
# Enums should be explicitly assigned their raw values
# - explicit_enum_raw_value
# Explicitly calling .init() should be avoided
- explicit_init
# Instance variables and functions should be explicitly accessed with ‘self.’
- explicit_self
# Top-level declarations should specify Access Control Level keywords explicitly
# - explicit_top_level_acl
# Properties should have a type interface
# - explicit_type_interface
# Prefer to use extension access modifiers
# - extension_access_modifier
# Fallthrough should be avoided
- fallthrough
# A fatalError call should have a message
# - fatal_error_message
# Header comments should be consistent with project patterns.
# The SWIFTLINT_CURRENT_FILENAME placeholder can optionally be used in the required and forbidden patterns.
# It will be replaced by the real file name.
# - file_header
# Files should not span too many lines
# - file_length
# File name should match a type or extension declared in the file (if any)
# - file_name
# File name should not contain any whitespace
- file_name_no_space
# Specifies how the types within a file should be ordered
# - file_types_order
# Prefer using .first(where:) over .filter { }.first in collections
- first_where
# Prefer flatMap over map followed by reduce([], +)
- flatmap_over_map_reduce
# where clauses are preferred over a single if inside a for
- for_where
# Force casts should be avoided
- force_cast
# Force tries should be avoided
- force_try
# Force unwrapping should be avoided
- force_unwrapping
# Functions bodies should not span too many lines
- function_body_length
# Prefer to locate parameters with defaults toward the end of the parameter list
# - function_default_parameter_at_end
# Number of function parameters should be low
# - function_parameter_count
# Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length
- generic_type_name
# Extensions shouldn’t add @IBInspectable properties
# - ibinspectable_in_extension
# Comparing two identical operands is likely a mistake
- identical_operands
# 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
- identifier_name
# Computed read-only properties and subscripts should avoid using the get keyword
- implicit_getter
# Prefer implicit returns in closures, functions and getters
# - implicit_return
# Implicitly unwrapped optionals should be avoided when possible
- implicitly_unwrapped_optional
# Identifiers should use inclusive language that avoids discrimination against groups of people based on race, gender, or socioeconomic status
# - inclusive_language
# Indent code using either one tab or the configured amount of spaces, unindent to match previous indentations. Don’t indent the first line
# - indentation_width
# If defer is at the end of its parent scope, it will be executed right where it is anyway
# - inert_defer
# Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty
- is_disjoint
# Discouraged explicit usage of the default separator
# - joined_default_parameter
# Tuples shouldn’t have too many members. Create a custom type instead
- large_tuple
# Prefer using .last(where:) over .filter { }.last in collections
- last_where
# Files should not contain leading whitespace
- leading_whitespace
# Struct extension properties and methods are preferred over legacy functions
- legacy_cggeometry_functions
# Struct-scoped constants are preferred over legacy global constants
- legacy_constant
# Swift constructors are preferred over legacy convenience functions
- legacy_constructor
# Prefer using the hash(into:) function instead of overriding hashValue
- legacy_hashing
# Prefer using the isMultiple(of:) function instead of using the remainder operator (%)
- legacy_multiple
# Struct extension properties and methods are preferred over legacy functions
- legacy_nsgeometry_functions
# Prefer using type.random(in:) over legacy functions
- legacy_random
# Let and var should be separated from other statements by a blank line
# - let_var_whitespace
# Lines should not span too many characters
- line_length
# Array and dictionary literal end should have the same indentation as the line that started it
- literal_expression_end_indentation
# Ensure definitions have a lower access control level than their enclosing parent
- lower_acl_than_parent
# MARK comment should be in valid format. e.g. ‘// MARK: …’ or ‘// MARK: - …’
- mark
# Public declarations should be documented
- missing_docs
# Modifier order should be consistent
# - modifier_order // Already enforced by swiftformat
# Arguments should be either on the same line, or one per line
- multiline_arguments
# Multiline arguments should have their surrounding brackets in a new line
# - multiline_arguments_brackets
# Chained function calls should be either on the same line, or one per line
- multiline_function_chains
# Multiline literals should have their surrounding brackets in a new line
- multiline_literal_brackets
# Functions and methods parameters should be either on the same line, or one per line
- multiline_parameters
# Multiline parameters should have their surrounding brackets in a new line
- multiline_parameters_brackets
# Trailing closure syntax should not be used when passing more than one closure argument
- multiple_closures_with_trailing_closure
# Types should be nested at most 1 level deep, and functions should be nested at most 2 levels deep
# - nesting
# Prefer Nimble operator overloads over free matcher functions
# - nimble_operator
# Prefer not to use extension access modifiers
# - no_extension_access_modifier
# Fallthroughs can only be used if the case contains at least one other statement
# - no_fallthrough_only
# Extensions shouldn’t be used to group code within the same source file
# - no_grouping_extension
# Don’t add a space between the method name and the parentheses
- no_space_in_method_call
# An object should only remove itself as an observer in deinit
# - notification_center_detachment
# Static strings should be used as key/comment in NSLocalizedString in order for genstrings to work
# - nslocalizedstring_key
# Calls to NSLocalizedString should specify the bundle which contains the strings file
# - nslocalizedstring_require_bundle
# NSObject subclasses should implement isEqual instead of ==
# - nsobject_prefer_isequal
# Underscores should be used as thousand separator in large decimal numbers
# - number_separator
# Prefer object literals over image and color inits
# - object_literal
# Opening braces should be preceded by a single space and on the same line as the declaration
# - opening_brace
# Operators should be surrounded by a single whitespace when they are being used
- operator_usage_whitespace
# Operators should be surrounded by a single whitespace when defining them
- operator_whitespace
# Matching an enum case against an optional enum without ‘?’ is supported on Swift 5.1 and above
- optional_enum_case_matching
# A doc comment should be attached to a declaration
- orphaned_doc_comment
# Some overridden methods should always call super
- overridden_super_call
# Extensions shouldn’t override declarations
# - override_in_extension
# Combine multiple pattern matching bindings by moving keywords out of tuples
# - pattern_matching_keywords
# Prefer Nimble matchers over XCTAssert functions
# - prefer_nimble
# Prefer Self over type(of: self) when accessing properties or calling methods
- prefer_self_type_over_type_of_self
# Prefer .zero over explicit init with zero parameters (e.g. CGPoint(x: 0, y: 0))
- prefer_zero_over_explicit_init
# Top-level constants should be prefixed by k
# - prefixed_toplevel_constant
# IBActions should be private
# - private_action
# IBOutlets should be private to avoid leaking UIKit to higher layers
# - private_outlet
# Prefer private over fileprivate declarations
# - private_over_fileprivate
# Combine Subject should be private
# - private_subject
# Unit tests marked private are silently skipped
# - private_unit_test
# Creating views using Interface Builder should be avoided
# - prohibited_interface_builder
# Some methods should not call super
- prohibited_super_call
# When declaring properties in protocols, the order of accessors should be get set
- protocol_property_accessors_order
# Discouraged call inside ‘describe’ and/or ‘context’ block
# - quick_discouraged_call
# Discouraged focused test. Other tests won’t run while this one is focused
# - quick_discouraged_focused_test
# Discouraged pending test. This test won’t run while it’s marked as pending
# - quick_discouraged_pending_test
# Camel cased cases of Codable String enums should have raw value
# - raw_value_for_camel_cased_codable_enum
# Prefer using .allSatisfy() or .contains() over reduce(true) or reduce(false)
- reduce_boolean
# Prefer reduce(into:_:) over reduce(_:_:) for copy-on-write types
- reduce_into
# Prefer _ = foo() over let _ = foo() when discarding a result from a function
- redundant_discardable_let
# nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant
- redundant_nil_coalescing
# Objective-C attribute (@objc) is redundant in declaration
- redundant_objc_attribute
# Initializing an optional variable with nil is redundant
- redundant_optional_initialization
# Property setter access level shouldn’t be explicit if it’s the same as the variable access level
# - redundant_set_access_control
# String enum values can be omitted when they are equal to the enumcase name
- redundant_string_enum_value
# Variables should not have redundant type annotation
- redundant_type_annotation
# Returning Void in a function declaration is redundant
- redundant_void_return
# Classes should have an explicit deinit method
# - required_deinit
# Enums conforming to a specified protocol must implement a specific case(s)
# - required_enum_case
# Return arrow and return type should be separated by a single space or on a separate line
- return_arrow_whitespace
# Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning
- shorthand_operator
# Test files should contain a single QuickSpec or XCTestCase class
# - single_test_class
# Prefer using min() or max() over sorted().first or sorted().last
- sorted_first_last
# Imports should be sorted.
# - sorted_imports // Already enforced by swiftformat
# Else and catch should be on the same line, one space after the previous declaration
- statement_position
# Operators should be declared as static functions, not free functions
- static_operator
# fileprivate should be avoided
# - strict_fileprivate
# @IBOutlets shouldn’t be declared as weak
# - strong_iboutlet
# SwiftLint ‘disable’ commands are superfluous when the disabled rule would not have triggered a violation
# in the disabled region. Use “ - ” if you wish to document a command
- superfluous_disable_command
# Case statements should vertically align with their enclosing switch statement, or indented if configured otherwise
- switch_case_alignment
# Cases inside a switch should always be on a newline
# - switch_case_on_newline
# Shorthand syntactic sugar should be used, i.e. [Int] instead of Array
- syntactic_sugar
# Test cases should only contain private non-test members
# - test_case_accessibility
# TODOs and FIXMEs should be resolved
- todo
# Prefer someBool.toggle() over someBool = !someBool
- toggle_bool
# Trailing closure syntax should be used whenever possible
# - trailing_closure
# Trailing commas in arrays and dictionaries should be avoided/enforced
# - trailing_comma
# Files should have a single trailing newline
- trailing_newline
# Lines should not have trailing semicolons
- trailing_semicolon
# Lines should not have trailing whitespace
- trailing_whitespace
# Type bodies should not span too many lines
# - type_body_length
# Specifies the order of subtypes, properties, methods & more within a type
# - type_contents_order
# Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length
- type_name
# Unimplemented functions should be marked as unavailable
# - unavailable_function
# Avoid using unneeded break statements
- unneeded_break_in_switch
# Parentheses are not needed when declaring closure arguments
- unneeded_parentheses_in_closure_argument
# Prefer capturing references as weak to avoid potential crashes
# - unowned_variable_capture
# Catch statements should not declare error variables without type casting
# - untyped_error_in_catch
# Unused reference in a capture list should be removed
- unused_capture_list
# Unused parameter in a closure should be replaced with _
- unused_closure_parameter
# Unused control flow label should be removed
- unused_control_flow_label
# Declarations should be referenced at least once within all files linted
- unused_declaration
# When the index or the item is not used, .enumerated() can be removed
- unused_enumerated
# All imported modules should be required to make the file compile
- unused_import
# Prefer != nil over let _ =
- unused_optional_binding
# Setter value is not used
- unused_setter_value
# @IBInspectable should be applied to variables only, have its type explicit and be of a supported type
# - valid_ibinspectable
# Function parameters should be aligned vertically if they’re in multiple lines in a declaration.
# - vertical_parameter_alignment
# Function parameters should be aligned vertically if they’re in multiple lines in a method call
# - vertical_parameter_alignment_on_call
# Limit vertical whitespace to a single empty line
- vertical_whitespace
# Include a single empty line between switch cases
# - vertical_whitespace_between_cases
# Don’t include vertical whitespace (empty line) before closing braces
- vertical_whitespace_closing_braces
# Don’t include vertical whitespace (empty line) after opening braces
- vertical_whitespace_opening_braces
# Prefer -> Void over -> ()
- void_return
# Delegates should be weak to avoid reference cycles
- weak_delegate
# Prefer specific XCTest matchers over XCTAssertEqual and XCTAssertNotEqual
- xct_specific_matcher
# An XCTFail call should include a description of the assertion
- xctfail_message
# The variable should be placed on the left, the constant on the right of a comparison operator.
- yoda_condition
line_length: 130
identifier_name:
min_length: 1
max_length: 60
type_name:
min_length: 1
max_length: 60
generic_type_name:
max_length: 35
function_body_length:
warning: 100