diff --git a/CHANGELOG.md b/CHANGELOG.md index e88065da6e..2560a83aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,11 @@ The next release will require Swift 4.0 or higher to build. [Ornithologist Coder](https://github.com/ornithocoder) [#2011](https://github.com/realm/SwiftLint/issues/2011) +* Add `redundant_set_access_control` rule to warn against using redundant + setter ACLs on variable declarations. + [Marcelo Fabri](https://github.com/marcelofabri) + [#1869](https://github.com/realm/SwiftLint/issues/1869) + #### Bug Fixes * Fix some cases where `colon` rule wouldn't be autocorrected. diff --git a/Rules.md b/Rules.md index ab2b5c706d..57e3cd13d8 100644 --- a/Rules.md +++ b/Rules.md @@ -92,6 +92,7 @@ * [Redundant Discardable Let](#redundant-discardable-let) * [Redundant Nil Coalescing](#redundant-nil-coalescing) * [Redundant Optional Initialization](#redundant-optional-initialization) +* [Redundant Set Access Control Rule](#redundant-set-access-control-rule) * [Redundant String Enum Value](#redundant-string-enum-value) * [Redundant Void Return](#redundant-void-return) * [Required Enum Case](#required-enum-case) @@ -132,9 +133,9 @@ ## Array Init -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`array_init` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`array_init` | Disabled | No | lint | 3.0.0 Prefer using Array(seq) than seq.map { $0 } to convert a sequence into an Array. @@ -241,9 +242,9 @@ foo.something { RouteMapper.map($0) } ## Attributes -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`attributes` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`attributes` | Disabled | No | style | 3.0.0 Attributes should be on their own lines in functions and types, but on the same line as variables and imports. @@ -594,9 +595,9 @@ private let bar = 1 ## Block Based KVO -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`block_based_kvo` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`block_based_kvo` | Enabled | No | idiomatic | 3.0.0 Prefer the new block based KVO API with keypaths when using Swift 3.2 or later. @@ -637,9 +638,9 @@ class Foo: NSObject { ## Class Delegate Protocol -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`class_delegate_protocol` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`class_delegate_protocol` | Enabled | No | lint | 3.0.0 Delegate protocols should be class-only so they can be weakly referenced. @@ -714,9 +715,9 @@ protocol FooDelegate: NSObjectProtocol {} ## Closing Brace Spacing -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`closing_brace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`closing_brace` | Enabled | Yes | style | 3.0.0 Closing brace with closing parenthesis should not have any whitespaces in the middle. @@ -753,9 +754,9 @@ Closing brace with closing parenthesis should not have any whitespaces in the mi ## Closure End Indentation -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`closure_end_indentation` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`closure_end_indentation` | Disabled | No | style | 3.0.0 Closure end should have the same indentation as the line that started it. @@ -830,9 +831,9 @@ return match(pattern: pattern, with: [.comment]).flatMap { range in ## Closure Parameter Position -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`closure_parameter_position` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`closure_parameter_position` | Enabled | No | style | 3.0.0 Closure parameters should be on the same line as opening brace. @@ -980,9 +981,9 @@ let mediaView: UIView = { [weak self] index in ## Closure Spacing -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`closure_spacing` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`closure_spacing` | Disabled | Yes | style | 3.0.0 Closure expressions should have a single space inside each brace. @@ -1033,9 +1034,9 @@ filter ↓{ sorted ↓{ $0 < $1}} ## Colon -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`colon` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`colon` | Enabled | Yes | style | 3.0.0 Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. @@ -1444,9 +1445,9 @@ func foo() { let dict = [1↓ : 1] } ## Comma Spacing -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`comma` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`comma` | Enabled | Yes | style | 3.0.0 There should be no space before and one after any comma. @@ -1519,9 +1520,9 @@ let result = plus( ## Compiler Protocol Init -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`compiler_protocol_init` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`compiler_protocol_init` | Enabled | No | lint | 3.0.0 The initializers declared in compiler protocols such as `ExpressibleByArrayLiteral` shouldn't be called directly. @@ -1560,9 +1561,9 @@ let set = ↓Set.init(arrayLiteral: 1, 2) ## Conditional Returns on Newline -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`conditional_returns_on_newline` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`conditional_returns_on_newline` | Disabled | No | style | 3.0.0 Conditional statements should always return on the next line @@ -1639,9 +1640,9 @@ if true { // return } ## Contains over first not nil -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`contains_over_first_not_nil` | Disabled | No | performance +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`contains_over_first_not_nil` | Disabled | No | performance | 3.0.0 Prefer `contains` over `first(where:) != nil` @@ -1700,9 +1701,9 @@ let first = myList.first { $0 % 2 == 0 } ## Control Statement -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`control_statement` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`control_statement` | Enabled | No | style | 3.0.0 if,for,while,do,catch statements shouldn't wrap their conditionals or arguments in parentheses. @@ -1892,9 +1893,9 @@ do { ## Custom Rules -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`custom_rules` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`custom_rules` | Enabled | No | style | 3.0.0 Create custom rules by providing a regex string. Optionally specify what syntax kinds to match against, the severity level, and what message to display. @@ -1902,9 +1903,9 @@ Create custom rules by providing a regex string. Optionally specify what syntax ## Cyclomatic Complexity -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`cyclomatic_complexity` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`cyclomatic_complexity` | Enabled | No | metrics | 3.0.0 Complexity of function bodies should be limited. @@ -1978,9 +1979,9 @@ if true {}; if true {}; if true {}; if true {}; if true {} ## Discarded Notification Center Observer -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`discarded_notification_center_observer` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`discarded_notification_center_observer` | Enabled | No | lint | 3.0.0 When registering for a notification using a block, the opaque observer that is returned should be stored so it can be removed later. @@ -2033,9 +2034,9 @@ func foo() -> Any { ## Discouraged Direct Initialization -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`discouraged_direct_init` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`discouraged_direct_init` | Enabled | No | lint | 3.0.0 Discouraged direct initialization of types that can be harmful. @@ -2118,9 +2119,9 @@ let foo = bar(bundle: ↓Bundle.init(), device: ↓UIDevice.init()) ## Discouraged Object Literal -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`discouraged_object_literal` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`discouraged_object_literal` | Disabled | No | idiomatic | 3.0.0 Prefer initializers over object literals. @@ -2171,9 +2172,9 @@ let color = ↓#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200 ## Discouraged Optional Boolean -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`discouraged_optional_boolean` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`discouraged_optional_boolean` | Disabled | No | idiomatic | 3.0.0 Prefer non-optional booleans over optional booleans. @@ -2804,9 +2805,9 @@ enum Foo { ## Discouraged Optional Collection -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`discouraged_optional_collection` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`discouraged_optional_collection` | Disabled | No | idiomatic | 3.0.0 Prefer empty collection over optional collection. @@ -3719,9 +3720,9 @@ enum Foo { ## Dynamic Inline -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`dynamic_inline` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`dynamic_inline` | Enabled | No | lint | 3.0.0 Avoid using 'dynamic' and '@inline(__always)' together. @@ -3788,9 +3789,9 @@ dynamic ## Empty Count -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`empty_count` | Disabled | No | performance +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`empty_count` | Disabled | No | performance | 3.0.0 Prefer checking `isEmpty` over comparing `count` to zero. @@ -3859,9 +3860,9 @@ order.discount == 0 ## Empty Enum Arguments -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`empty_enum_arguments` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`empty_enum_arguments` | Enabled | Yes | style | 3.0.0 Arguments can be omitted when matching enums with associated types if they are not used. @@ -3961,9 +3962,9 @@ func example(foo: Foo) { ## Empty Parameters -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`empty_parameters` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`empty_parameters` | Enabled | Yes | style | 3.0.0 Prefer `() -> ` over `Void -> `. @@ -4032,9 +4033,9 @@ let foo: ↓(Void) -> () throws -> Void) ## Empty Parentheses with Trailing Closure -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`empty_parentheses_with_trailing_closure` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`empty_parentheses_with_trailing_closure` | Enabled | Yes | style | 3.0.0 When using trailing closures, empty parentheses should be avoided after the method call. @@ -4118,9 +4119,9 @@ func foo() -> [Int] { ## Empty String -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`empty_string` | Disabled | No | performance +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`empty_string` | Disabled | No | performance | 3.0.0 Prefer checking `isEmpty` over comparing `string` to an empty string literal. @@ -4155,9 +4156,9 @@ myString↓ != "" ## Explicit ACL -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`explicit_acl` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`explicit_acl` | Disabled | No | idiomatic | 3.0.0 All declarations should specify Access Control Level keywords explicitly. @@ -4270,9 +4271,9 @@ func b() {} ## Explicit Enum Raw Value -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`explicit_enum_raw_value` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`explicit_enum_raw_value` | Disabled | No | idiomatic | 3.0.0 Enums should be explicitly assigned their raw values. @@ -4367,9 +4368,9 @@ enum Numbers: Decimal { ## Explicit Init -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`explicit_init` | Disabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`explicit_init` | Disabled | Yes | idiomatic | 3.0.0 Explicitly calling .init() should be avoided. @@ -4422,9 +4423,9 @@ func foo() -> [String] { ## Explicit Top Level ACL -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`explicit_top_level_acl` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`explicit_top_level_acl` | Disabled | No | idiomatic | 3.0.0 Top-level declarations should specify Access Control Level keywords explicitly. @@ -4504,9 +4505,9 @@ func b() {} ## Explicit Type Interface -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`explicit_type_interface` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`explicit_type_interface` | Disabled | No | idiomatic | 3.0.0 Properties should have a type interface @@ -4583,9 +4584,9 @@ class Foo { ## Extension Access Modifier -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`extension_access_modifier` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`extension_access_modifier` | Disabled | No | idiomatic | 3.0.0 Prefer to use extension access modifiers @@ -4673,9 +4674,9 @@ public extension Foo { ## Fallthrough -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`fallthrough` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`fallthrough` | Enabled | No | idiomatic | 3.0.0 Fallthrough should be avoided. @@ -4710,9 +4711,9 @@ case .bar2: ## Fatal Error Message -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`fatal_error_message` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`fatal_error_message` | Disabled | No | idiomatic | 3.0.0 A fatalError call should have a message. @@ -4759,9 +4760,9 @@ func foo() { ## File Header -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`file_header` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`file_header` | Disabled | No | style | 3.0.0 Header comments should be consistent with project patterns. @@ -4813,9 +4814,9 @@ let foo = 2 ## File Line Length -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`file_length` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`file_length` | Enabled | No | metrics | 3.0.0 Files should not span too many lines. @@ -6048,9 +6049,9 @@ print("swiftlint") ## First Where -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`first_where` | Disabled | No | performance +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`first_where` | Disabled | No | performance | 3.0.0 Prefer using `.first(where:)` over `.filter { }.first` in collections. @@ -6125,9 +6126,9 @@ match(pattern: pattern).filter { $0.first == .identifier } ## For Where -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`for_where` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`for_where` | Enabled | No | idiomatic | 3.0.0 `where` clauses are preferred over a single `if` inside a `for`. @@ -6227,9 +6228,9 @@ for user in users { ## Force Cast -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`force_cast` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`force_cast` | Enabled | No | idiomatic | 3.0.0 Force casts should be avoided. @@ -6258,9 +6259,9 @@ NSNumber() ↓as! Int ## Force Try -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`force_try` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`force_try` | Enabled | No | idiomatic | 3.0.0 Force tries should be avoided. @@ -6287,9 +6288,9 @@ func a() throws {}; ↓try! a() ## Force Unwrapping -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`force_unwrapping` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`force_unwrapping` | Disabled | No | idiomatic | 3.0.0 Force unwrapping should be avoided. @@ -6430,9 +6431,9 @@ open var computed: String { return foo.bar↓! } ## Function Body Length -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`function_body_length` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`function_body_length` | Enabled | No | metrics | 3.0.0 Functions bodies should not span too many lines. @@ -6440,9 +6441,9 @@ Functions bodies should not span too many lines. ## Function Parameter Count -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`function_parameter_count` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`function_parameter_count` | Enabled | No | metrics | 3.0.0 Number of function parameters should be low. @@ -6520,9 +6521,9 @@ init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ## Generic Type Name -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`generic_type_name` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`generic_type_name` | Enabled | No | idiomatic | 3.0.0 Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length. @@ -6721,9 +6722,9 @@ enum Foo<↓type> {} ## Identifier Name -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`identifier_name` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`identifier_name` | Enabled | No | style | 3.0.0 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. @@ -6834,9 +6835,9 @@ enum Foo { case ↓MyEnum } ## Implicit Getter -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`implicit_getter` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`implicit_getter` | Enabled | No | style | 3.0.0 Computed read-only properties and subscripts should avoid using the get keyword. @@ -7037,9 +7038,9 @@ class Foo { ## Implicit Return -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`implicit_return` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`implicit_return` | Disabled | Yes | style | 3.0.0 Prefer implicit returns in closures. @@ -7098,9 +7099,9 @@ foo.map { ## Implicitly Unwrapped Optional -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`implicitly_unwrapped_optional` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`implicitly_unwrapped_optional` | Disabled | No | idiomatic | 3.0.0 Implicitly unwrapped optionals should be avoided when possible. @@ -7187,9 +7188,9 @@ func foo(int: Int!) {} ## Is Disjoint -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`is_disjoint` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`is_disjoint` | Enabled | No | idiomatic | 3.0.0 Prefer using `Set.isDisjoint(with:)` over `Set.intersection(_:).isEmpty`. @@ -7232,9 +7233,9 @@ let isObjc = !objcAttributes.↓intersection(dictionary.enclosedSwiftAttributes) ## Joined Default Parameter -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`joined_default_parameter` | Disabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`joined_default_parameter` | Disabled | Yes | idiomatic | 3.0.0 Discouraged explicit usage of the default separator. @@ -7280,9 +7281,9 @@ func foo() -> String { ## Large Tuple -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`large_tuple` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`large_tuple` | Enabled | No | metrics | 3.0.0 Tuples shouldn't have too many members. Create a custom type instead. @@ -7441,9 +7442,9 @@ func getDictionaryAndInt() -> (Dictionary, Int ## Leading Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`leading_whitespace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`leading_whitespace` | Enabled | Yes | style | 3.0.0 Files should not contain leading whitespace. @@ -7477,9 +7478,9 @@ Files should not contain leading whitespace. ## Legacy CGGeometry Functions -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`legacy_cggeometry_functions` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`legacy_cggeometry_functions` | Enabled | Yes | idiomatic | 3.0.0 Struct extension properties and methods are preferred over legacy functions @@ -7658,9 +7659,9 @@ rect1.intersects(rect2) ## Legacy Constant -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`legacy_constant` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`legacy_constant` | Enabled | Yes | idiomatic | 3.0.0 Struct-scoped constants are preferred over legacy global constants. @@ -7759,9 +7760,9 @@ Float.pi ## Legacy Constructor -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`legacy_constructor` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`legacy_constructor` | Enabled | Yes | idiomatic | 3.0.0 Swift constructors are preferred over legacy convenience functions. @@ -7966,9 +7967,9 @@ UIOffset(horizontal: horizontal, vertical: vertical) ## Legacy NSGeometry Functions -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`legacy_nsgeometry_functions` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`legacy_nsgeometry_functions` | Enabled | Yes | idiomatic | 3.0.0 Struct extension properties and methods are preferred over legacy functions @@ -8139,9 +8140,9 @@ rect1.intersects(rect2) ## Variable Declaration Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`let_var_whitespace` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`let_var_whitespace` | Disabled | No | style | 3.0.0 Let and var should be separated from other statements by a blank line. @@ -8304,9 +8305,9 @@ var x = 0 ## Line Length -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`line_length` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`line_length` | Enabled | No | metrics | 3.0.0 Lines should not span too many characters. @@ -8355,9 +8356,9 @@ Lines should not span too many characters. ## Literal Expression End Indentation -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`literal_expression_end_indentation` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`literal_expression_end_indentation` | Disabled | No | style | 3.0.0 Array and dictionary literal end should have the same indentation as the line that started it. @@ -8444,9 +8445,9 @@ let x = [ ## Lower ACL than parent -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`lower_acl_than_parent` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`lower_acl_than_parent` | Disabled | No | lint | 3.0.0 Ensure definitions have a lower access control level than their enclosing parent @@ -8521,9 +8522,9 @@ class Foo { public private(set) var bar: String? } ## Mark -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`mark` | Enabled | Yes | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`mark` | Enabled | Yes | lint | 3.0.0 MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...' @@ -8646,9 +8647,9 @@ extension MarkTest {} ## Multiline Arguments -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`multiline_arguments` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`multiline_arguments` | Disabled | No | style | 3.0.0 Arguments should be either on the same line, or one per line. @@ -8771,9 +8772,9 @@ foo( ## Multiline Parameters -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`multiline_parameters` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`multiline_parameters` | Disabled | No | style | 3.0.0 Functions and methods parameters should be either on the same line, or one per line. @@ -9251,9 +9252,9 @@ class Foo { ## Multiple Closures with Trailing Closure -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`multiple_closures_with_trailing_closure` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`multiple_closures_with_trailing_closure` | Enabled | No | style | 3.0.0 Trailing closure syntax should not be used when passing more than one closure argument. @@ -9312,9 +9313,9 @@ UIView.animate(withDuration: 1.0, animations: { ## Nesting -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`nesting` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`nesting` | Enabled | No | metrics | 3.0.0 Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep. @@ -9429,9 +9430,9 @@ func func4() { func func5() { ## Nimble Operator -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`nimble_operator` | Disabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`nimble_operator` | Disabled | Yes | idiomatic | 3.0.0 Prefer Nimble operator overloads over free matcher functions. @@ -9544,9 +9545,9 @@ expect(10) > 2 ## No Extension Access Modifier -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`no_extension_access_modifier` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`no_extension_access_modifier` | Disabled | No | idiomatic | 3.0.0 Prefer not to use extension access modifiers @@ -9596,9 +9597,9 @@ extension String {} ## No Grouping Extension -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`no_grouping_extension` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`no_grouping_extension` | Disabled | No | idiomatic | 3.0.0 Extensions shouldn't be used to group code within the same source file. @@ -9653,9 +9654,9 @@ extension External { struct Gotcha {}} ## Notification Center Detachment -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`notification_center_detachment` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`notification_center_detachment` | Enabled | No | lint | 3.0.0 An object should only remove itself as an observer in `deinit`. @@ -9701,9 +9702,9 @@ class Foo { ## Number Separator -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`number_separator` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`number_separator` | Disabled | Yes | style | 3.0.0 Underscores should be used as thousand separator in large decimal numbers. @@ -9962,9 +9963,9 @@ let foo = ↓1000000.000000_1 ## Object Literal -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`object_literal` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`object_literal` | Disabled | No | idiomatic | 3.0.0 Prefer object literals over image and color inits. @@ -10079,9 +10080,9 @@ let color = ↓NSColor.init(white: 0.5, alpha: 1) ## Opening Brace Spacing -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`opening_brace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`opening_brace` | Enabled | Yes | style | 3.0.0 Opening braces should be preceded by a single space and on the same line as the declaration. @@ -10244,9 +10245,9 @@ struct Parent { ## Operator Usage Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`operator_usage_whitespace` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`operator_usage_whitespace` | Disabled | Yes | style | 3.0.0 Operators should be surrounded by a single whitespace when they are being used. @@ -10419,9 +10420,9 @@ let v8 = 1↓ << (6) ## Operator Function Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`operator_whitespace` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`operator_whitespace` | Enabled | No | style | 3.0.0 Operators should be surrounded by a single whitespace when defining them. @@ -10485,9 +10486,9 @@ func abc(lhs: Int, rhs: Int) -> Int {} ## Overridden methods call super -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`overridden_super_call` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`overridden_super_call` | Disabled | No | lint | 3.0.0 Some overridden methods should always call super @@ -10582,9 +10583,9 @@ class VC: UIViewController { ## Override in Extension -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`override_in_extension` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`override_in_extension` | Disabled | No | lint | 3.0.0 Extensions shouldn't override declarations. @@ -10656,9 +10657,9 @@ extension Person { ## Pattern Matching Keywords -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`pattern_matching_keywords` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`pattern_matching_keywords` | Disabled | No | idiomatic | 3.0.0 Combine multiple pattern matching bindings by moving keywords out of tuples. @@ -10779,9 +10780,9 @@ switch foo { ## Prefixed Top-Level Constant -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`prefixed_toplevel_constant` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`prefixed_toplevel_constant` | Disabled | No | style | 3.0.0 Top-level constants should be prefixed by `k`. @@ -10898,9 +10899,9 @@ let ↓foo = { ## Private Actions -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`private_action` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`private_action` | Disabled | No | lint | 3.0.0 IBActions should be private. @@ -11038,9 +11039,9 @@ internal extension Foo { ## Private Outlets -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`private_outlet` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`private_outlet` | Disabled | No | lint | 3.0.0 IBOutlets should be private to avoid leaking UIKit to higher layers. @@ -11108,9 +11109,9 @@ class Foo { ## Private over fileprivate -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`private_over_fileprivate` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`private_over_fileprivate` | Enabled | Yes | idiomatic | 3.0.0 Prefer `private` over `fileprivate` declarations. @@ -11187,9 +11188,9 @@ fileprivate(set) var myInt = 4 ## Private Unit Test -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`private_unit_test` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`private_unit_test` | Enabled | No | lint | 3.0.0 Unit tests marked private are silently skipped. @@ -11280,9 +11281,9 @@ public class FooTest: XCTestCase { func test1() {} ## Prohibited calls to super -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`prohibited_super_call` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`prohibited_super_call` | Disabled | No | lint | 3.0.0 Some methods should not call super @@ -11358,9 +11359,9 @@ class VC: NSView { ## Protocol Property Accessors Order -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`protocol_property_accessors_order` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`protocol_property_accessors_order` | Enabled | Yes | style | 3.0.0 When declaring properties in protocols, the order of accessors should be `get set`. @@ -11403,9 +11404,9 @@ protocol Foo { ## Quick Discouraged Call -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`quick_discouraged_call` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`quick_discouraged_call` | Disabled | No | lint | 3.0.0 Discouraged call inside 'describe' and/or 'context' block. @@ -11746,9 +11747,9 @@ class TotoTests: QuickSpec { ## Quick Discouraged Focused Test -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`quick_discouraged_focused_test` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`quick_discouraged_focused_test` | Disabled | No | lint | 3.0.0 Discouraged focused test. Other tests won't run while this one is focused. @@ -11854,9 +11855,9 @@ class TotoTests: QuickSpec { ## Quick Discouraged Pending Test -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`quick_discouraged_pending_test` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`quick_discouraged_pending_test` | Disabled | No | lint | 3.0.0 Discouraged pending test. This test won't run while it's marked as pending. @@ -11971,9 +11972,9 @@ class TotoTests: QuickSpec { ## Redundant Discardable Let -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`redundant_discardable_let` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_discardable_let` | Enabled | Yes | style | 3.0.0 Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function. @@ -12026,9 +12027,9 @@ if _ = foo() { ↓let _ = bar() } ## Redundant Nil Coalescing -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`redundant_nil_coalescing` | Disabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_nil_coalescing` | Disabled | Yes | idiomatic | 3.0.0 nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant @@ -12062,9 +12063,9 @@ var myVar: Int? = nil; myVar↓??nil ## Redundant Optional Initialization -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`redundant_optional_initialization` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_optional_initialization` | Enabled | Yes | idiomatic | 3.0.0 Initializing an optional variable with nil is redundant. @@ -12156,11 +12157,70 @@ var myVar: Optional↓=nil +## Redundant Set Access Control Rule + +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_set_access_control` | Enabled | No | idiomatic | 4.1.0 + +Property setter access level shouldn't be explicit if it's the same as the variable access level. + +### Examples + +
+Non Triggering Examples + +```swift +private(set) public var foo: Int +``` + +```swift +public let foo: Int +``` + +```swift +public var foo: Int +``` + +```swift +var foo: Int +``` + +
+
+Triggering Examples + +```swift +↓private(set) private var foo: Int +``` + +```swift +↓fileprivate(set) fileprivate var foo: Int +``` + +```swift +↓internal(set) internal var foo: Int +``` + +```swift +↓public(set) public var foo: Int +``` + +```swift +open class Foo { + ↓open(set) open var bar: Int +} +``` + +
+ + + ## Redundant String Enum Value -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`redundant_string_enum_value` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_string_enum_value` | Enabled | No | idiomatic | 3.0.0 String enum values can be omitted when they are equal to the enumcase name. @@ -12240,9 +12300,9 @@ enum Numbers: String { ## Redundant Void Return -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`redundant_void_return` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`redundant_void_return` | Enabled | Yes | idiomatic | 3.0.0 Returning Void in a function declaration is redundant. @@ -12340,9 +12400,9 @@ protocol Foo { ## Required Enum Case -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`required_enum_case` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`required_enum_case` | Disabled | No | lint | 3.0.0 Enums conforming to a specified protocol must implement a specific case(s). @@ -12415,9 +12475,9 @@ enum MyNetworkResponse: String, NetworkResponsable { ## Returning Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`return_arrow_whitespace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`return_arrow_whitespace` | Enabled | Yes | style | 3.0.0 Return arrow and return type should be separated by a single space or on a separate line. @@ -12508,9 +12568,9 @@ var abc = {(param: Int)↓->Bool in } ## Shorthand Operator -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`shorthand_operator` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`shorthand_operator` | Enabled | No | style | 3.0.0 Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. @@ -12778,9 +12838,9 @@ n = n - i / outputLength ## Single Test Class -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`single_test_class` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`single_test_class` | Disabled | No | style | 3.0.0 Test files should contain a single QuickSpec or XCTestCase class. @@ -12853,9 +12913,9 @@ class TotoTests { } ## Min or Max over Sorted First or Last -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`sorted_first_last` | Disabled | No | performance +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`sorted_first_last` | Disabled | No | performance | 3.0.0 Prefer using `min()` or `max()` over `sorted().first` or `sorted().last` @@ -12964,9 +13024,9 @@ let min = myList.max(by: { $0 < $1 }) ## Sorted Imports -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`sorted_imports` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`sorted_imports` | Disabled | Yes | style | 3.0.0 Imports should be sorted. @@ -13071,9 +13131,9 @@ import BBB ## Statement Position -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`statement_position` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`statement_position` | Enabled | Yes | style | 3.0.0 Else and catch should be on the same line, one space after the previous declaration. @@ -13140,9 +13200,9 @@ catch { ## Strict fileprivate -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`strict_fileprivate` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`strict_fileprivate` | Disabled | No | idiomatic | 3.0.0 `fileprivate` should be avoided. @@ -13223,9 +13283,9 @@ struct Inter { ## Superfluous Disable Command -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`superfluous_disable_command` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`superfluous_disable_command` | Enabled | No | lint | 3.0.0 SwiftLint 'disable' commands are superfluous when the disabled rule would not have triggered a violation in the disabled region. @@ -13233,9 +13293,9 @@ SwiftLint 'disable' commands are superfluous when the disabled rule would not ha ## Switch and Case Statement Alignment -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`switch_case_alignment` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`switch_case_alignment` | Enabled | No | style | 3.0.0 Case statements should vertically align with the enclosing switch statement. @@ -13326,9 +13386,9 @@ case 1: ## Switch Case on Newline -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`switch_case_on_newline` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`switch_case_on_newline` | Disabled | No | style | 3.0.0 Cases inside a switch should always be on a newline @@ -13527,9 +13587,9 @@ switch foo { ## Syntactic Sugar -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`syntactic_sugar` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`syntactic_sugar` | Enabled | No | idiomatic | 3.0.0 Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. @@ -13640,9 +13700,9 @@ let x: ↓Swift.Optional ## Todo -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`todo` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`todo` | Enabled | No | lint | 3.0.0 TODOs and FIXMEs should be resolved. @@ -13711,9 +13771,9 @@ TODOs and FIXMEs should be resolved. ## Trailing Closure -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`trailing_closure` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`trailing_closure` | Disabled | No | style | 3.0.0 Trailing closure syntax should be used whenever possible. @@ -13782,9 +13842,9 @@ offsets.sorted { $0.offset < $1.offset } ## Trailing Comma -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`trailing_comma` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`trailing_comma` | Enabled | Yes | style | 3.0.0 Trailing commas in arrays and dictionaries should be avoided/enforced. @@ -13884,9 +13944,9 @@ let foo = ["אבג", "αβγ", "🇺🇸"↓,] ## Trailing Newline -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`trailing_newline` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`trailing_newline` | Enabled | Yes | style | 3.0.0 Files should have a single trailing newline. @@ -13920,9 +13980,9 @@ let a = 0 ## Trailing Semicolon -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`trailing_semicolon` | Enabled | Yes | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`trailing_semicolon` | Enabled | Yes | idiomatic | 3.0.0 Lines should not have trailing semicolons. @@ -13972,9 +14032,9 @@ let a = 0↓; ; ; ## Trailing Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`trailing_whitespace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`trailing_whitespace` | Enabled | Yes | style | 3.0.0 Lines should not have trailing whitespace. @@ -14028,9 +14088,9 @@ let name: String ## Type Body Length -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`type_body_length` | Enabled | No | metrics +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`type_body_length` | Enabled | No | metrics | 3.0.0 Type bodies should not span too many lines. @@ -17154,9 +17214,9 @@ let abc = 0 ## Type Name -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`type_name` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`type_name` | Enabled | No | idiomatic | 3.0.0 Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length. @@ -17331,9 +17391,9 @@ protocol Foo { ## Unneeded Break in Switch -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`unneeded_break_in_switch` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`unneeded_break_in_switch` | Enabled | No | idiomatic | 3.0.0 Avoid using unneeded break statements. @@ -17419,9 +17479,9 @@ case .foo, .foo2 where condition: ## Unneeded Parentheses in Closure Argument -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`unneeded_parentheses_in_closure_argument` | Disabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`unneeded_parentheses_in_closure_argument` | Disabled | Yes | style | 3.0.0 Parentheses are not needed when declaring closure arguments. @@ -17483,9 +17543,9 @@ foo.bar { [weak self] ↓(x, y) in } ## Untyped Error in Catch -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`untyped_error_in_catch` | Disabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`untyped_error_in_catch` | Disabled | No | idiomatic | 3.0.0 Catch statements should not declare error variables without type casting. @@ -17573,9 +17633,9 @@ do { ## Unused Closure Parameter -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`unused_closure_parameter` | Enabled | Yes | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`unused_closure_parameter` | Enabled | Yes | lint | 3.0.0 Unused parameter in a closure should be replaced with _. @@ -17733,9 +17793,9 @@ func foo () { ## Unused Enumerated -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`unused_enumerated` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`unused_enumerated` | Enabled | No | idiomatic | 3.0.0 When the index or the item is not used, `.enumerated()` can be removed. @@ -17819,9 +17879,9 @@ for (idx, ↓_) in bar.enumerated() { } ## Unused Optional Binding -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`unused_optional_binding` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`unused_optional_binding` | Enabled | No | style | 3.0.0 Prefer `!= nil` over `let _ =` @@ -17929,9 +17989,9 @@ if case .some(let ↓_) = self {} ## Valid IBInspectable -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`valid_ibinspectable` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`valid_ibinspectable` | Enabled | No | lint | 3.0.0 @IBInspectable should be applied to variables only, have its type explicit and be of a supported type @@ -18062,9 +18122,9 @@ class Foo { ## Vertical Parameter Alignment -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`vertical_parameter_alignment` | Enabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`vertical_parameter_alignment` | Enabled | No | style | 3.0.0 Function parameters should be aligned vertically if they're in multiple lines in a declaration. @@ -18166,9 +18226,9 @@ func validateFunction(_ file: File, ## Vertical Parameter Alignment On Call -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`vertical_parameter_alignment_on_call` | Disabled | No | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`vertical_parameter_alignment_on_call` | Disabled | No | style | 3.0.0 Function parameters should be aligned vertically if they're in multiple lines in a method call. @@ -18280,9 +18340,9 @@ foo(param1: 1, param2: { _ in }, ## Vertical Whitespace -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`vertical_whitespace` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`vertical_whitespace` | Enabled | Yes | style | 3.0.0 Limit vertical whitespace to a single empty line. @@ -18348,9 +18408,9 @@ class BBBB {} ## Void Return -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`void_return` | Enabled | Yes | style +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`void_return` | Enabled | Yes | style | 3.0.0 Prefer `-> Void` over `-> ()`. @@ -18439,9 +18499,9 @@ let foo: (ConfigurationTests) -> () throws -> ↓()) ## Weak Delegate -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`weak_delegate` | Enabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`weak_delegate` | Enabled | No | lint | 3.0.0 Delegates should be weak to avoid reference cycles. @@ -18540,9 +18600,9 @@ class Foo { ## XCTFail Message -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`xctfail_message` | Enabled | No | idiomatic +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`xctfail_message` | Enabled | No | idiomatic | 3.0.0 An XCTFail call should include a description of the assertion. @@ -18585,9 +18645,9 @@ func testFoo() { ## Yoda condition rule -Identifier | Enabled by default | Supports autocorrection | Kind ---- | --- | --- | --- -`yoda_condition` | Disabled | No | lint +Identifier | Enabled by default | Supports autocorrection | Kind | Minimum Swift Compiler Version +--- | --- | --- | --- | --- +`yoda_condition` | Disabled | No | lint | 3.0.0 The variable should be placed on the left, the constant on the right of a comparison operator. diff --git a/Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift b/Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift index d91c001622..afae80bc5c 100644 --- a/Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift +++ b/Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift @@ -72,10 +72,18 @@ extension Dictionary where Key: ExpressibleByStringLiteral { return (self["key.usr"] as? Int64).flatMap({ Int($0) }) } + var attribute: String? { + return self["key.attribute"] as? String + } + var enclosedSwiftAttributes: [String] { + return swiftAttributes.compactMap { $0.attribute } + } + + var swiftAttributes: [[String: SourceKitRepresentable]] { let array = self["key.attributes"] as? [SourceKitRepresentable] ?? [] let dictionaries = array.compactMap { ($0 as? [String: SourceKitRepresentable]) } - return dictionaries.compactMap { $0["key.attribute"] as? String } + return dictionaries } var substructure: [[String: SourceKitRepresentable]] { diff --git a/Source/SwiftLintFramework/Models/MasterRuleList.swift b/Source/SwiftLintFramework/Models/MasterRuleList.swift index eff12eeee8..073f9a6601 100644 --- a/Source/SwiftLintFramework/Models/MasterRuleList.swift +++ b/Source/SwiftLintFramework/Models/MasterRuleList.swift @@ -100,6 +100,7 @@ public let masterRuleList = RuleList(rules: [ RedundantDiscardableLetRule.self, RedundantNilCoalescingRule.self, RedundantOptionalInitializationRule.self, + RedundantSetAccessControlRule.self, RedundantStringEnumValueRule.self, RedundantVoidReturnRule.self, RequiredEnumCaseRule.self, diff --git a/Source/SwiftLintFramework/Models/RuleDescription.swift b/Source/SwiftLintFramework/Models/RuleDescription.swift index e6a5585626..155582f424 100644 --- a/Source/SwiftLintFramework/Models/RuleDescription.swift +++ b/Source/SwiftLintFramework/Models/RuleDescription.swift @@ -15,6 +15,7 @@ public struct RuleDescription: Equatable { public let triggeringExamples: [String] public let corrections: [String: String] public let deprecatedAliases: Set + public let minSwiftVersion: SwiftVersion public var consoleDescription: String { return "\(name) (\(identifier)): \(description)" } @@ -23,6 +24,7 @@ public struct RuleDescription: Equatable { } public init(identifier: String, name: String, description: String, kind: RuleKind, + minSwiftVersion: SwiftVersion = .three, nonTriggeringExamples: [String] = [], triggeringExamples: [String] = [], corrections: [String: String] = [:], deprecatedAliases: Set = []) { @@ -34,6 +36,7 @@ public struct RuleDescription: Equatable { self.triggeringExamples = triggeringExamples self.corrections = corrections self.deprecatedAliases = deprecatedAliases + self.minSwiftVersion = minSwiftVersion } } diff --git a/Source/SwiftLintFramework/Models/RuleList+Documentation.swift b/Source/SwiftLintFramework/Models/RuleList+Documentation.swift index 2916e94159..df09e78b6e 100644 --- a/Source/SwiftLintFramework/Models/RuleList+Documentation.swift +++ b/Source/SwiftLintFramework/Models/RuleList+Documentation.swift @@ -67,13 +67,16 @@ extension RuleList { } private func detailsSummary(_ rule: Rule) -> String { - var content = "Identifier | Enabled by default | Supports autocorrection | Kind \n" - content += "--- | --- | --- | ---\n" + let columns = ["Identifier", "Enabled by default", "Supports autocorrection", + "Kind", "Minimum Swift Compiler Version"] + var content = columns.joined(separator: " | ") + "\n" + content += columns.map { _ in "---" }.joined(separator: " | ") + "\n" let identifier = type(of: rule).description.identifier let defaultStatus = rule is OptInRule ? "Disabled" : "Enabled" let correctable = rule is CorrectableRule ? "Yes" : "No" let kind = type(of: rule).description.kind - content += "`\(identifier)` | \(defaultStatus) | \(correctable) | \(kind)\n\n" + let minSwiftVersion = type(of: rule).description.minSwiftVersion.rawValue + content += "`\(identifier)` | \(defaultStatus) | \(correctable) | \(kind) | \(minSwiftVersion) \n\n" return content } diff --git a/Source/SwiftLintFramework/Models/SwiftVersion.swift b/Source/SwiftLintFramework/Models/SwiftVersion.swift index 707bf4a779..4a51ac2fd5 100644 --- a/Source/SwiftLintFramework/Models/SwiftVersion.swift +++ b/Source/SwiftLintFramework/Models/SwiftVersion.swift @@ -9,24 +9,24 @@ import Foundation import SourceKittenFramework -struct SwiftVersion: RawRepresentable { - typealias RawValue = String +public struct SwiftVersion: RawRepresentable { + public typealias RawValue = String - let rawValue: String + public let rawValue: String - init(rawValue: String) { + public init(rawValue: String) { self.rawValue = rawValue } } extension SwiftVersion: Comparable { // Comparable - static func < (lhs: SwiftVersion, rhs: SwiftVersion) -> Bool { + public static func < (lhs: SwiftVersion, rhs: SwiftVersion) -> Bool { return lhs.rawValue < rhs.rawValue } } -extension SwiftVersion { +public extension SwiftVersion { static let three = SwiftVersion(rawValue: "3.0.0") static let four = SwiftVersion(rawValue: "4.0.0") static let fourDotOne = SwiftVersion(rawValue: "4.1.0") diff --git a/Source/SwiftLintFramework/Rules/RedundantSetAccessControlRule.swift b/Source/SwiftLintFramework/Rules/RedundantSetAccessControlRule.swift new file mode 100644 index 0000000000..c9239bef38 --- /dev/null +++ b/Source/SwiftLintFramework/Rules/RedundantSetAccessControlRule.swift @@ -0,0 +1,64 @@ +// +// RedundantSetAccessControlRule.swift +// SwiftLint +// +// Created by Marcelo Fabri on 02/03/18. +// Copyright © 2018 Realm. All rights reserved. +// + +import Foundation +import SourceKittenFramework + +public struct RedundantSetAccessControlRule: ASTRule, ConfigurationProviderRule { + public var configuration = SeverityConfiguration(.warning) + + public init() {} + + public static let description = RuleDescription( + identifier: "redundant_set_access_control", + name: "Redundant Set Access Control Rule", + description: "Property setter access level shouldn't be explicit if " + + "it's the same as the variable access level.", + kind: .idiomatic, + minSwiftVersion: .fourDotOne, + nonTriggeringExamples: [ + "private(set) public var foo: Int", + "public let foo: Int", + "public var foo: Int", + "var foo: Int" + ], + triggeringExamples: [ + "↓private(set) private var foo: Int", + "↓fileprivate(set) fileprivate var foo: Int", + "↓internal(set) internal var foo: Int", + "↓public(set) public var foo: Int", + """ + open class Foo { + ↓open(set) open var bar: Int + } + """ + ] + ) + + public func validate(file: File, kind: SwiftDeclarationKind, + dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] { + guard SwiftDeclarationKind.variableKinds.contains(kind), + dictionary.setterAccessibility == dictionary.accessibility else { + return [] + } + + let explicitSetACL = dictionary.swiftAttributes.first { dict in + return dict.attribute?.hasPrefix("source.decl.attribute.setter_access") ?? false + } + + guard let offset = explicitSetACL?.offset else { + return [] + } + + return [ + StyleViolation(ruleDescription: type(of: self).description, + severity: configuration.severity, + location: Location(file: file, byteOffset: offset)) + ] + } +} diff --git a/SwiftLint.xcodeproj/project.pbxproj b/SwiftLint.xcodeproj/project.pbxproj index 418e5dfd7c..a06ae1f08e 100644 --- a/SwiftLint.xcodeproj/project.pbxproj +++ b/SwiftLint.xcodeproj/project.pbxproj @@ -208,6 +208,7 @@ D48AE2CC1DFB58C5001C6A4A /* AttributesRulesExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48AE2CB1DFB58C5001C6A4A /* AttributesRulesExamples.swift */; }; D48B51211F4F5DEF0068AB98 /* RuleList+Documentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B51201F4F5DEF0068AB98 /* RuleList+Documentation.swift */; }; D48B51231F4F5E4B0068AB98 /* DocumentationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B51221F4F5E4B0068AB98 /* DocumentationTests.swift */; }; + D49896F12026B36C00814A83 /* RedundantSetAccessControlRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49896F02026B36C00814A83 /* RedundantSetAccessControlRule.swift */; }; D4998DE71DF191380006E05D /* AttributesRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE61DF191380006E05D /* AttributesRuleTests.swift */; }; D4998DE91DF194F20006E05D /* FileHeaderRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE81DF194F20006E05D /* FileHeaderRuleTests.swift */; }; D4A893351E15824100BF954D /* SwiftVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A893341E15824100BF954D /* SwiftVersion.swift */; }; @@ -589,6 +590,7 @@ D48AE2CB1DFB58C5001C6A4A /* AttributesRulesExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributesRulesExamples.swift; sourceTree = ""; }; D48B51201F4F5DEF0068AB98 /* RuleList+Documentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RuleList+Documentation.swift"; sourceTree = ""; }; D48B51221F4F5E4B0068AB98 /* DocumentationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentationTests.swift; sourceTree = ""; }; + D49896F02026B36C00814A83 /* RedundantSetAccessControlRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedundantSetAccessControlRule.swift; sourceTree = ""; }; D4998DE61DF191380006E05D /* AttributesRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributesRuleTests.swift; sourceTree = ""; }; D4998DE81DF194F20006E05D /* FileHeaderRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHeaderRuleTests.swift; sourceTree = ""; }; D4A893341E15824100BF954D /* SwiftVersion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftVersion.swift; sourceTree = ""; }; @@ -1152,6 +1154,7 @@ D4C889701E385B7B00BAE88D /* RedundantDiscardableLetRule.swift */, 24B4DF0B1D6DFA370097803B /* RedundantNilCoalescingRule.swift */, D4B022951E0EF80C007E5297 /* RedundantOptionalInitializationRule.swift */, + D49896F02026B36C00814A83 /* RedundantSetAccessControlRule.swift */, D41E7E0A1DF9DABB0065259A /* RedundantStringEnumValueRule.swift */, D4B022B11E10B613007E5297 /* RedundantVoidReturnRule.swift */, B89F3BC91FD5ED9000931E59 /* RequiredEnumCaseRule.swift */, @@ -1711,6 +1714,7 @@ D40F83881DE9179200524C62 /* TrailingCommaConfiguration.swift in Sources */, 827169B31F488181003FB9AF /* ExplicitEnumRawValueRule.swift in Sources */, 62FE5D32200CABDD00F68793 /* DiscouragedOptionalCollectionRuleExamples.swift in Sources */, + D49896F12026B36C00814A83 /* RedundantSetAccessControlRule.swift in Sources */, 29FFC37A1F15764D007E4825 /* FileLengthRuleConfiguration.swift in Sources */, 3B5B9FE11C444DA20009AD27 /* Array+SwiftLint.swift in Sources */, 8FD216CC205584AF008ED13F /* CharacterSet+SwiftLint.swift in Sources */, diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index b16447f9b1..b6e3035047 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -493,6 +493,7 @@ extension RulesTests { ("testRedundantDiscardableLet", testRedundantDiscardableLet), ("testRedundantNilCoalescing", testRedundantNilCoalescing), ("testRedundantOptionalInitialization", testRedundantOptionalInitialization), + ("testRedundantSetAccessControl", testRedundantSetAccessControl), ("testRedundantStringEnumValue", testRedundantStringEnumValue), ("testRedundantVoidReturn", testRedundantVoidReturn), ("testRequiredEnumCase", testRequiredEnumCase), diff --git a/Tests/SwiftLintFrameworkTests/RulesTests.swift b/Tests/SwiftLintFrameworkTests/RulesTests.swift index 32b3fb3e4c..f643394f98 100644 --- a/Tests/SwiftLintFrameworkTests/RulesTests.swift +++ b/Tests/SwiftLintFrameworkTests/RulesTests.swift @@ -330,6 +330,10 @@ class RulesTests: XCTestCase { verifyRule(RedundantOptionalInitializationRule.description) } + func testRedundantSetAccessControl() { + verifyRule(RedundantSetAccessControlRule.description) + } + func testRedundantStringEnumValue() { verifyRule(RedundantStringEnumValueRule.description) } diff --git a/Tests/SwiftLintFrameworkTests/TestHelpers.swift b/Tests/SwiftLintFrameworkTests/TestHelpers.swift index 2fc0900921..8880dfcdc4 100644 --- a/Tests/SwiftLintFrameworkTests/TestHelpers.swift +++ b/Tests/SwiftLintFrameworkTests/TestHelpers.swift @@ -167,6 +167,10 @@ extension XCTestCase { return } + guard SwiftVersion.current >= ruleDescription.minSwiftVersion else { + return + } + let triggers = ruleDescription.triggeringExamples let nonTriggers = ruleDescription.nonTriggeringExamples verifyExamples(triggers: triggers, nonTriggers: nonTriggers, configuration: config)