-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path.swiftlint.yml
231 lines (227 loc) · 18.2 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
# Acts as a whitelist, only the rules specified in this list will be enabled. Can not be specified alongside disabled_rules or opt_in_rules.
whitelist_rules:
- anyobject_protocol # Prefer using AnyObject over class for class-only protocols.
- attributes # Attributes should be on their own lines in functions and types, but on the same line as variables and imports.
- block_based_kvo # Prefer the new block based KVO API with keypaths when using Swift 3.2 or later
- class_delegate_protocol # Delegate protocols should be class-only so they can be weakly referenced.
- closure_body_length # Closure bodies should not span too many lines.
- closing_brace # Closing brace with closing parenthesis should not have any whitespaces in the middle.
- closure_end_indentation # Closure end should have the same indentation as the line that started it.
- closure_spacing # Closure expressions should have a single space inside each brace.
- colon # Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.
- comma # There should be no space before and one after any comma.
- compiler_protocol_init # The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn't be called directly.
- contains_over_first_not_nil # Prefer contains over first(where:) != nil and firstIndex(where:) != nil.
- control_statement # if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses.
- convenience_type # Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation.
- custom_rules # See details below.
- cyclomatic_complexity # Complexity of function bodies should be limited.
- discarded_notification_center_observer # When registering for a notification using a block, the opaque observer that is returned should be stored so it can be removed later.
- discouraged_direct_init # Discouraged direct initialization of types that can be harmful.
- duplicate_enum_cases # Enum can't contain multiple cases with the same name.
- duplicate_imports # Imports should be unique.
- dynamic_inline # Avoid using 'dynamic' and '@inline(__always)' together.
- empty_count # Prefer checking isEmpty over comparing count to zero.
- empty_enum_arguments # Arguments can be omitted when matching enums with associated types if they are not used.
- empty_parameters # Prefer () -> over Void -> .
- empty_parentheses_with_trailing_closure # When using trailing closures, empty parentheses should be avoided after the method call.
- empty_string # Prefer checking isEmpty over comparing string to an empty string literal.
- empty_xctest_method # Empty XCTest method should be avoided.
- fatal_error_message # A fatalError call should have a message.
- file_length # Files should not span too many lines.
- first_where # Prefer using .first(where:) over .filter { }.first in collections.
- for_where # where clauses are preferred over a single if inside a for.
- function_body_length # Functions bodies should not span too many lines.
- 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.
- identical_operands # Comparing two identical operands is likely a mistake.
- 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.
- implicit_getter # Computed read-only properties and subscripts should avoid using the get keyword.
- implicit_return # Prefer implicit returns in closures.
- inert_defer # If defer is at the end of its parent scope, it will be executed right where it is anyway.
- is_disjoint # Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty.
- joined_default_parameter # Discouraged explicit usage of the default separator.
- large_tuple # Tuples shouldn't have too many members. Create a custom type instead.
- last_where # Prefer using .last(where:) over .filter { }.last in collections.
- leading_whitespace # Files should not contain leading whitespace.
- legacy_cggeometry_functions # Struct extension properties and methods are preferred over legacy functions
- legacy_constant # Struct-scoped constants are preferred over legacy global constants.
- legacy_constructor # Swift constructors are preferred over legacy convenience functions.
- legacy_hashing # Prefer using the hash(into:) function instead of overriding hashValue
- legacy_multiple # Prefer using the isMultiple(of:) function instead of using the remainder operator (%) (from Swift 5.0)
- legacy_nsgeometry_functions # Struct extension properties and methods are preferred over legacy functions
- legacy_random # Prefer using type.random(in:) over legacy functions.
- let_var_whitespace # Let and var should be separated from other statements by a blank line.
- literal_expression_end_indentation # Array and dictionary literal end should have the same indentation as the line that started it.
- lower_acl_than_parent # Ensure definitions have a lower access control level than their enclosing parent
- mark # MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...'
- modifier_order # Modifier order should be consistent.
- multiline_function_chains # Chained function calls should be either on the same line, or one per line.
- multiline_literal_brackets # Multiline literals should have their surrounding brackets in a new line.
- multiline_parameters_brackets # Multiline parameters should have their surrounding brackets in a new line.
- multiple_closures_with_trailing_closure # Trailing closure syntax should not be used when passing more than one closure argument.
- nimble_operator # Prefer Nimble operator overloads over free matcher functions.
- notification_center_detachment # An object should only remove itself as an observer in deinit.
- nslocalizedstring_key # Static strings should be used as key in NSLocalizedString in order to genstrings work.
- nslocalizedstring_require_bundle # Calls to NSLocalizedString should specify the bundle which contains the strings file.
- nsobject_prefer_isequal # NSObject subclasses should implement isEqual instead of ==.
- opening_brace # Opening braces should be preceded by a single space and on the same line as the declaration.
- operator_usage_whitespace # Operators should be surrounded by a single whitespace when they are being used.
- operator_whitespace # Operators should be surrounded by a single whitespace when defining them.
- overridden_super_call # Some overridden methods should always call super
- private_outlet # IBOutlets should be private to avoid leaking UIKit to higher layers.
- private_over_fileprivate # Prefer private over fileprivate declarations.
- private_unit_test # Unit tests marked private are silently skipped.
- prohibited_super_call # Some methods should not call super
- protocol_property_accessors_order # When declaring properties in protocols, the order of accessors should be get set.
- reduce_boolean # Prefer using .allSatisfy() or .contains() over reduce(true) or reduce(false)
- reduce_into # Prefer reduce(into:_:) over reduce(_:_:) for copy-on-write types
- redundant_discardable_let # Prefer _ = foo() over let _ = foo() when discarding a result from a function.
- redundant_nil_coalescing # nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant
- redundant_objc_attribute # Objective-C attribute (@objc) is redundant in declaration.
- redundant_optional_initialization # Initializing an optional variable with nil is redundant.
- redundant_set_access_control # Property setter access level shouldn't be explicit if it's the same as the variable access level.
- redundant_string_enum_value # String enum values can be omitted when they are equal to the enumcase name.
- redundant_void_return # Returning Void in a function declaration is redundant.
- return_arrow_whitespace # Return arrow and return type should be separated by a single space or on a separate line.
- shorthand_operator # Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning.
- single_test_class # Test files should contain a single QuickSpec or XCTestCase class.
- sorted_first_last # Prefer using min() or max() over sorted().first or sorted().last
- sorted_imports # Imports should be sorted.
- statement_position # Else and catch should be on the same line, one space after the previous declaration.
- superfluous_disable_command # SwiftLint 'disable' commands are superfluous when the disabled rule would not have triggered a violation in the disabled region.
- switch_case_alignment # Case statements should vertically align with their enclosing switch statement, or indented if configured otherwise.
- syntactic_sugar # Shorthand syntactic sugar should be used, i.e. [Int] instead of Array.
- toggle_bool # Prefer someBool.toggle() over someBool = !someBool.
- trailing_closure # Trailing closure syntax should be used whenever possible.
- trailing_newline # Files should have a single trailing newline.
- trailing_semicolon # Lines should not have trailing semicolons.
- trailing_whitespace # Lines should not have trailing whitespace.
- type_body_length # Type bodies should not span too many lines.
- type_name # Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length.
- unneeded_break_in_switch # Avoid using unneeded break statements.
- unneeded_parentheses_in_closure_argument # Parentheses are not needed when declaring closure arguments.
- untyped_error_in_catch # Catch statements should not declare error variables without type casting.
- unused_capture_list # Unused reference in a capture list should be removed.
- unused_closure_parameter # Unused parameter in a closure should be replaced with _.
- unused_control_flow_label # Unused control flow label should be removed.
- unused_enumerated # When the index or the item is not used, .enumerated() can be removed.
- unused_optional_binding # Prefer != nil over let _ =
- unused_setter_value # Setter value is not used.
- valid_ibinspectable # @IBInspectable should be applied to variables only, have its type explicit and be of a supported type
- vertical_parameter_alignment # Function parameters should be aligned vertically if they're in multiple lines in a declaration.
- vertical_whitespace_closing_braces # Don't include vertical whitespace (empty line) before closing braces.
- vertical_whitespace_opening_braces # Don't include vertical whitespace (empty line) after opening braces.
- void_return # Prefer -> Void over -> ().
- xct_specific_matcher # Prefer specific XCTest matchers over XCTAssertEqual and XCTAssertNotEqual
- xctfail_message # An XCTFail call should include a description of the assertion.
# This is an entirely separate list of rules that are only run by the analyze command. All analyzer rules are opt-in, so this is the only configurable rule list (there is no disabled/whitelist equivalent).
analyzer_rules:
- unused_private_declaration # Private declarations should be referenced in that file.
- unused_import # All imported modules should be required to make the file compile.
- explicit_self # Instance variables and functions should be explicitly accessed with 'self.'.
# Configuration for rules
closure_body_length:
warning: 50
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.
excluded:
- dt
- id
- t
- p0
- p1
- p2
- p3
file_length:
warning: 1000
function_body_length:
warning: 100
type_body_length:
warning: 500
# Disable rules from the default enabled set
#disabled_rules:
# - array_init # Prefer using Array(seq) over seq.map { $0 } to convert a sequence into an Array.
# - closure_body_length # Closure bodies should not span too many lines.
# - collection_alignment # All elements in a collection literal should be vertically aligned
# - conditional_returns_on_newline # Conditional statements should always return on the next line
# - deployment_target # Availability checks or attributes shouldn't be using older versions that are satisfied by the deployment target.
# - discouraged_object_literal # Prefer initializers over object literals.
# - discouraged_optional_boolean # Prefer non-optional booleans over optional booleans.
# - discouraged_optional_collection # Prefer empty collection over optional collection.
# - explicit_acl # All declarations should specify Access Control Level keywords explicitly.
# - explicit_enum_raw_value # Enums should be explicitly assigned their raw values.
# - explicit_init # Explicitly calling .init() should be avoided.
# - explicit_top_level_acl # Top-level declarations should specify Access Control Level keywords explicitly.
# - explicit_type_interface # Properties should have a type interface
# - extension_access_modifier # Prefer to use extension access modifiers
# - fallthrough # Fallthrough should be avoided.
# - file_header # 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_length # Files should not span too many lines.
# - file_name # File name should match a type or extension declared in the file (if any).
# - file_types_order # Specifies how the types within a file should be ordered.
# - force_cast # Force casts should be avoided.
# - force_try # Force tries should be avoided.
# - force_unwrapping # Force unwrapping should be avoided.
# - function_body_length # Functions bodies should not span too many lines.
# - function_default_parameter_at_end # Prefer to locate parameters with defaults toward the end of the parameter list.
# - function_parameter_count # Number of function parameters should be low.
# - implicitly_unwrapped_optional # Implicitly unwrapped optionals should be avoided when possible.
# - line_length
# - missing_docs # Declarations should be documented.
# - multiline_arguments # Arguments should be either on the same line, or one per line.
# - multiline_arguments_brackets # Multiline arguments should have their surrounding brackets in a new line.
# - multiline_parameters # Functions and methods parameters should be either on the same line, or one per line.
# - multiline_parameters_brackets # Multiline parameters should have their surrounding brackets in a new line.
# - nesting # Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep.
# - no_extension_access_modifier # Prefer not to use extension access modifiers
# - no_fallthrough_only # Fallthroughs can only be used if the case contains at least one other statement.
# - no_grouping_extension # Extensions shouldn't be used to group code within the same source file.
# - number_separator # Underscores should be used as thousand separator in large decimal numbers.
# - object_literal # Prefer object literals over image and color inits.
# - override_in_extension # Extensions shouldn't override declarations.
# - pattern_matching_keywords # Combine multiple pattern matching bindings by moving keywords out of tuples.
# - prefixed_toplevel_constant # Top-level constants should be prefixed by k.
# - private_action # IBActions should be private.
# - prohibited_interface_builder # Creating views using Interface Builder should be avoided.
# - quick_discouraged_call # Discouraged call inside 'describe' and/or 'context' block.
# - quick_discouraged_focused_test # Discouraged focused test. Other tests won't run while this one is focused.
# - quick_discouraged_pending_test # Discouraged pending test. This test won't run while it's marked as pending.
# - redundant_type_annotation # Variables should not have redundant type annotation
# - required_deinit # Classes should have an explicit deinit method.
# - required_enum_case # Enums conforming to a specified protocol must implement a specific case(s).
# - static_operator # Operators should be declared as static functions, not free functions.
# - strict_fileprivate # fileprivate should be avoided.
# - strong_iboutlet # @IBOutlets shouldn't be declared as weak.
# - switch_case_on_newline # Cases inside a switch should always be on a newline
# - todo # TODOs and FIXMEs should be resolved.
# - trailing_comma # Trailing commas in arrays and dictionaries should be avoided/enforced.
# - type_body_length # Type bodies should not span too many lines.
# - type_contents_order # Specifies the order of subtypes, properties, methods & more within a type.
# - unavailable_function # Unimplemented functions should be marked as unavailable.
# - unowned_variable_capture # Prefer capturing references as weak to avoid potential crashes.
# - vertical_parameter_alignment_on_call # Function parameters should be aligned vertically if they're in multiple lines in a method call.
# - vertical_whitespace # Limit vertical whitespace to a single empty line.
# - vertical_whitespace_between_cases # Include a single empty line between switch cases.
# - weak_delegate # Delegates should be weak to avoid reference cycles.
# - yoda_condition # The variable should be placed on the left, the constant on the right of a comparison operator.
excluded: # paths to ignore during linting. Takes precedence over `included`.
- build
- Carthage
- Examples/Carthage
# Custom regex-based rules
custom_rules:
comments_space:
name: "Space After Comment"
regex: '(//\w+)'
message: "There should be a space after //"
match_kinds: comment
severity: warning
multiple_empty_lines:
name: "Multiple Empty Lines"
regex: '((?:\s*\n){4,})'
message: "There are too many line breaks"
severity: warning
unnecessary_type:
name: "Unnecessary Type"
regex: '[ a-zA-Z0-9]*(?:let|var) [ a-zA-Z0-9]*: ([a-zA-Z0-9]*)[\? ]*= \1'
message: "Type Definition Not Needed"
severity: warning