├── .editorconfig ├── .gitattributes ├── .swiftlint.yml ├── license └── readme.md /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | only_rules: 2 | - accessibility_trait_for_button 3 | - array_init 4 | - blanket_disable_command 5 | - block_based_kvo 6 | - class_delegate_protocol 7 | - closing_brace 8 | - closure_end_indentation 9 | - closure_parameter_position 10 | - closure_spacing 11 | - collection_alignment 12 | - colon 13 | - comma 14 | - comma_inheritance 15 | - compiler_protocol_init 16 | - computed_accessors_order 17 | - conditional_returns_on_newline 18 | - contains_over_filter_count 19 | - contains_over_filter_is_empty 20 | - contains_over_first_not_nil 21 | - contains_over_range_nil_comparison 22 | - control_statement 23 | - custom_rules 24 | - deployment_target 25 | - direct_return 26 | - discarded_notification_center_observer 27 | - discouraged_assert 28 | - discouraged_direct_init 29 | - discouraged_none_name 30 | - discouraged_object_literal 31 | - discouraged_optional_boolean 32 | - discouraged_optional_collection 33 | - duplicate_conditions 34 | - duplicate_enum_cases 35 | - duplicate_imports 36 | - duplicated_key_in_dictionary_literal 37 | - dynamic_inline 38 | - empty_collection_literal 39 | - empty_count 40 | - empty_enum_arguments 41 | - empty_parameters 42 | - empty_parentheses_with_trailing_closure 43 | - empty_string 44 | - empty_xctest_method 45 | - enum_case_associated_values_count 46 | - explicit_init 47 | - fallthrough 48 | - fatal_error_message 49 | - final_test_case 50 | - first_where 51 | - flatmap_over_map_reduce 52 | - for_where 53 | - generic_type_name 54 | - ibinspectable_in_extension 55 | - identical_operands 56 | - identifier_name 57 | - implicit_getter 58 | - implicit_return 59 | - inclusive_language 60 | - invalid_swiftlint_command 61 | - is_disjoint 62 | - joined_default_parameter 63 | - last_where 64 | - leading_whitespace 65 | - legacy_cggeometry_functions 66 | - legacy_constant 67 | - legacy_constructor 68 | - legacy_hashing 69 | - legacy_multiple 70 | - legacy_nsgeometry_functions 71 | - legacy_random 72 | - literal_expression_end_indentation 73 | - lower_acl_than_parent 74 | - mark 75 | - modifier_order 76 | - multiline_arguments 77 | - multiline_arguments_brackets 78 | - multiline_function_chains 79 | - multiline_literal_brackets 80 | - multiline_parameters 81 | - multiline_parameters_brackets 82 | - nimble_operator 83 | - no_extension_access_modifier 84 | - no_fallthrough_only 85 | - no_space_in_method_call 86 | - non_optional_string_data_conversion 87 | - non_overridable_class_declaration 88 | - notification_center_detachment 89 | - ns_number_init_as_function_reference 90 | - nsobject_prefer_isequal 91 | - number_separator 92 | - operator_usage_whitespace 93 | - operator_whitespace 94 | - optional_data_string_conversion 95 | - overridden_super_call 96 | - prefer_key_path 97 | - prefer_self_in_static_references 98 | - prefer_self_type_over_type_of_self 99 | - prefer_zero_over_explicit_init 100 | - private_action 101 | - private_outlet 102 | - private_subject 103 | - private_swiftui_state 104 | - private_unit_test 105 | - prohibited_super_call 106 | - protocol_property_accessors_order 107 | - reduce_boolean 108 | - reduce_into 109 | - redundant_discardable_let 110 | - redundant_nil_coalescing 111 | - redundant_objc_attribute 112 | - redundant_optional_initialization 113 | - redundant_sendable 114 | - redundant_set_access_control 115 | - redundant_string_enum_value 116 | - redundant_type_annotation 117 | - redundant_void_return 118 | - required_enum_case 119 | - return_arrow_whitespace 120 | - return_value_from_void_function 121 | - self_binding 122 | - self_in_property_initialization 123 | - shorthand_operator 124 | - shorthand_optional_binding 125 | - sorted_first_last 126 | - statement_position 127 | - static_operator 128 | - static_over_final_class 129 | - strong_iboutlet 130 | - superfluous_disable_command 131 | - superfluous_else 132 | - switch_case_alignment 133 | - switch_case_on_newline 134 | - syntactic_sugar 135 | - test_case_accessibility 136 | - toggle_bool 137 | - trailing_closure 138 | - trailing_comma 139 | - trailing_newline 140 | - trailing_semicolon 141 | - trailing_whitespace 142 | - unavailable_condition 143 | - unavailable_function 144 | - unneeded_break_in_switch 145 | - unneeded_override 146 | - unneeded_parentheses_in_closure_argument 147 | - unowned_variable_capture 148 | - untyped_error_in_catch 149 | - unused_closure_parameter 150 | - unused_control_flow_label 151 | - unused_enumerated 152 | - unused_optional_binding 153 | - unused_setter_value 154 | - valid_ibinspectable 155 | - vertical_parameter_alignment 156 | - vertical_parameter_alignment_on_call 157 | - vertical_whitespace_closing_braces 158 | - vertical_whitespace_opening_braces 159 | - void_function_in_ternary 160 | - void_return 161 | - xct_specific_matcher 162 | - xctfail_message 163 | - yoda_condition 164 | analyzer_rules: 165 | - capture_variable 166 | - typesafe_array_init 167 | - unneeded_synthesized_initializer 168 | - unused_declaration 169 | - unused_import 170 | redundant_discardable_let: 171 | ignore_swiftui_view_bodies: true 172 | for_where: 173 | allow_for_as_filter: true 174 | number_separator: 175 | minimum_length: 5 176 | identifier_name: 177 | max_length: 178 | warning: 100 179 | error: 100 180 | min_length: 181 | warning: 2 182 | error: 2 183 | allowed_symbols: 184 | - '_' 185 | excluded: 186 | - 'x' 187 | - 'y' 188 | - 'z' 189 | - 'a' 190 | - 'b' 191 | - 'x1' 192 | - 'x2' 193 | - 'y1' 194 | - 'y2' 195 | - 'z2' 196 | redundant_type_annotation: 197 | consider_default_literal_types_redundant: true 198 | unneeded_override: 199 | affect_initializers: true 200 | deployment_target: 201 | macOS_deployment_target: '14' 202 | iOS_deployment_target: '17' 203 | tvOS_deployment_target: '17' 204 | watchOS_deployment_target: '10' 205 | custom_rules: 206 | no_nsrect: 207 | regex: '\bNSRect\b' 208 | match_kinds: typeidentifier 209 | message: 'Use CGRect instead of NSRect' 210 | no_nssize: 211 | regex: '\bNSSize\b' 212 | match_kinds: typeidentifier 213 | message: 'Use CGSize instead of NSSize' 214 | no_nspoint: 215 | regex: '\bNSPoint\b' 216 | match_kinds: typeidentifier 217 | message: 'Use CGPoint instead of NSPoint' 218 | no_cgfloat: 219 | regex: '\bCGFloat\b' 220 | match_kinds: typeidentifier 221 | message: 'Use Double instead of CGFloat' 222 | no_cgfloat2: 223 | regex: '\bCGFloat\(' 224 | message: 'Use Double instead of CGFloat' 225 | swiftui_state_private: 226 | regex: '@(ObservedObject|EnvironmentObject)\s+var' 227 | message: 'SwiftUI @ObservedObject and @EnvironmentObject properties should be private' 228 | swiftui_environment_private: 229 | regex: '@Environment\(\\\.\w+\)\s+var' 230 | message: 'SwiftUI @Environment properties should be private' 231 | swiftui_scaledtofit: 232 | regex: 'aspectRatio\(contentMode: \.fit\)' 233 | message: 'Prefer `scaledToFit()`' 234 | swiftui_scaledtofill: 235 | regex: 'aspectRatio\(contentMode: \.fill\)' 236 | message: 'Prefer `scaledToFill()`' 237 | final_class: 238 | regex: '^class [a-zA-Z\d]+[^{]+\{' 239 | message: 'Classes should be marked as final whenever possible. If you actually need it to be subclassable, just add `// swiftlint:disable:next final_class`.' 240 | no_alignment_center: 241 | regex: '\b\(alignment: .center\b' 242 | message: 'This alignment is the default.' 243 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # swiftlint-config 2 | 3 | > Good starter config for [SwiftLint](https://github.com/realm/SwiftLint) 4 | 5 | SwiftLint has a lot of [rules](https://github.com/realm/SwiftLint) and it takes time to adjust them to something sensible. You probably don't want exactly what I have, but this should be a good starting point. This is what I use for all [my Swift projects](https://github.com/search?q=user%3Asindresorhus+language%3Aswift). 6 | 7 | ## Usage 8 | 9 | 1. Create a `.swiftlint.yml` file in the root of your project with the following: 10 | 11 | ``` 12 | parent_config: https://raw.githubusercontent.com/sindresorhus/swiftlint-config/main/.swiftlint.yml 13 | ``` 14 | 15 | *(Replace `main` with a specific commit hash if you want predictable builds)* 16 | 17 | 2. Follow the [SwiftLint setup instructions](https://github.com/realm/SwiftLint#installation). 18 | 19 | ## Badge 20 | 21 | Show off that you're using this config. 22 | 23 | ``` 24 | [![sindresorhus's SwiftLint config](https://img.shields.io/badge/SwiftLint-sindresorhus-hotpink.svg)](https://github.com/sindresorhus/swiftlint-config) 25 | ``` 26 | 27 | [![sindresorhus's SwiftLint config](https://img.shields.io/badge/SwiftLint-sindresorhus-hotpink.svg)](https://github.com/sindresorhus/swiftlint-config) 28 | --------------------------------------------------------------------------------