@@ -46,7 +46,7 @@ private extension NestingRule {
46
46
private var levels = Levels ( )
47
47
48
48
override func visit( _ node: ActorDeclSyntax ) -> SyntaxVisitorContinueKind {
49
- validate ( forFunction: false , triggeringToken: node. actorKeyword)
49
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. actorKeyword)
50
50
return . visitChildren
51
51
}
52
52
@@ -55,7 +55,7 @@ private extension NestingRule {
55
55
}
56
56
57
57
override func visit( _ node: ClassDeclSyntax ) -> SyntaxVisitorContinueKind {
58
- validate ( forFunction: false , triggeringToken: node. classKeyword)
58
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. classKeyword)
59
59
return . visitChildren
60
60
}
61
61
@@ -64,9 +64,7 @@ private extension NestingRule {
64
64
}
65
65
66
66
override func visit( _ node: EnumDeclSyntax ) -> SyntaxVisitorContinueKind {
67
- if !configuration. ignoreCodingKeys || !node. definesCodingKeys {
68
- validate ( forFunction: false , triggeringToken: node. enumKeyword)
69
- }
67
+ validate ( forFunction: false , definesCodingKeys: node. definesCodingKeys, triggeringToken: node. enumKeyword)
70
68
return . visitChildren
71
69
}
72
70
@@ -75,7 +73,7 @@ private extension NestingRule {
75
73
}
76
74
77
75
override func visit( _ node: ExtensionDeclSyntax ) -> SyntaxVisitorContinueKind {
78
- validate ( forFunction: false , triggeringToken: node. extensionKeyword)
76
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. extensionKeyword)
79
77
return . visitChildren
80
78
}
81
79
@@ -84,7 +82,7 @@ private extension NestingRule {
84
82
}
85
83
86
84
override func visit( _ node: FunctionDeclSyntax ) -> SyntaxVisitorContinueKind {
87
- validate ( forFunction: true , triggeringToken: node. funcKeyword)
85
+ validate ( forFunction: true , definesCodingKeys : false , triggeringToken: node. funcKeyword)
88
86
return . visitChildren
89
87
}
90
88
@@ -93,7 +91,7 @@ private extension NestingRule {
93
91
}
94
92
95
93
override func visit( _ node: ProtocolDeclSyntax ) -> SyntaxVisitorContinueKind {
96
- validate ( forFunction: false , triggeringToken: node. protocolKeyword)
94
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. protocolKeyword)
97
95
return . visitChildren
98
96
}
99
97
@@ -102,7 +100,7 @@ private extension NestingRule {
102
100
}
103
101
104
102
override func visit( _ node: StructDeclSyntax ) -> SyntaxVisitorContinueKind {
105
- validate ( forFunction: false , triggeringToken: node. structKeyword)
103
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. structKeyword)
106
104
return . visitChildren
107
105
}
108
106
@@ -115,15 +113,15 @@ private extension NestingRule {
115
113
if configuration. ignoreTypealiasesAndAssociatedtypes {
116
114
return
117
115
}
118
- validate ( forFunction: false , triggeringToken: node. typealiasKeyword)
116
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. typealiasKeyword)
119
117
levels. pop ( )
120
118
}
121
119
122
120
override func visitPost( _ node: AssociatedTypeDeclSyntax ) {
123
121
if configuration. ignoreTypealiasesAndAssociatedtypes {
124
122
return
125
123
}
126
- validate ( forFunction: false , triggeringToken: node. associatedtypeKeyword)
124
+ validate ( forFunction: false , definesCodingKeys : false , triggeringToken: node. associatedtypeKeyword)
127
125
levels. pop ( )
128
126
}
129
127
@@ -143,7 +141,7 @@ private extension NestingRule {
143
141
}
144
142
145
143
// MARK: -
146
- private func validate( forFunction: Bool , triggeringToken: TokenSyntax ) {
144
+ private func validate( forFunction: Bool , definesCodingKeys : Bool , triggeringToken: TokenSyntax ) {
147
145
let inFunction = levels. lastIsFunction
148
146
levels. push ( forFunction)
149
147
@@ -154,6 +152,12 @@ private extension NestingRule {
154
152
if configuration. alwaysAllowOneTypeInFunctions && inFunction && !forFunction {
155
153
return
156
154
}
155
+
156
+ // if current defines coding keys and we're ignoring coding keys, then skip nesting rule
157
+ if configuration. ignoreCodingKeys && definesCodingKeys {
158
+ return
159
+ }
160
+
157
161
guard let severity = configuration. severity ( with: targetLevel, for: level) else { return }
158
162
159
163
let targetName = forFunction ? " Functions " : " Types "
0 commit comments