File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
Tests/SwiftFormatRulesTests Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -46,17 +46,21 @@ public final class UseSynthesizedInitializer: SyntaxLintRule {
46
46
var extraneousInitializers = [ InitializerDeclSyntax] ( )
47
47
for initializer in initializers {
48
48
guard
49
+ // Attributes signify intent that isn't automatically synthesized by the compiler.
50
+ initializer. attributes. isEmpty,
49
51
matchesPropertyList (
50
52
parameters: initializer. signature. parameterClause. parameters,
51
- properties: storedProperties)
52
- else { continue }
53
- guard
53
+ properties: storedProperties) ,
54
54
matchesAssignmentBody (
55
55
variables: storedProperties,
56
- initBody: initializer. body)
57
- else { continue }
58
- guard matchesAccessLevel ( modifiers: initializer. modifiers, properties: storedProperties)
59
- else { continue }
56
+ initBody: initializer. body) ,
57
+ matchesAccessLevel (
58
+ modifiers: initializer. modifiers,
59
+ properties: storedProperties)
60
+ else {
61
+ continue
62
+ }
63
+
60
64
extraneousInitializers. append ( initializer)
61
65
}
62
66
Original file line number Diff line number Diff line change @@ -404,4 +404,22 @@ final class UseSynthesizedInitializerTests: LintOrFormatRuleTestCase {
404
404
XCTAssertDiagnosed ( . removeRedundantInitializer, line: 15 )
405
405
XCTAssertDiagnosed ( . removeRedundantInitializer, line: 25 )
406
406
}
407
+
408
+ func testMemberwiseInitializerWithAttributeIsNotDiagnosed( ) {
409
+ let input =
410
+ """
411
+ public struct Person {
412
+ let phoneNumber: String
413
+ let address: String
414
+
415
+ @inlinable init(phoneNumber: String, address: String) {
416
+ self.address = address
417
+ self.phoneNumber = phoneNumber
418
+ }
419
+ }
420
+ """
421
+
422
+ performLint ( UseSynthesizedInitializer . self, input: input)
423
+ XCTAssertNotDiagnosed ( . removeRedundantInitializer)
424
+ }
407
425
}
You can’t perform that action at this time.
0 commit comments