@@ -36,6 +36,7 @@ public struct Configuration: Codable, Equatable {
36
36
case indentSwitchCaseLabels
37
37
case rules
38
38
case spacesAroundRangeFormationOperators
39
+ case noAssignmentInExpressions
39
40
}
40
41
41
42
/// The version of this configuration.
@@ -147,6 +148,9 @@ public struct Configuration: Codable, Equatable {
147
148
/// `...` and `..<`.
148
149
public var spacesAroundRangeFormationOperators = false
149
150
151
+ /// Contains exceptions for the `NoAssignmentInExpressions` rule.
152
+ public var noAssignmentInExpressions = NoAssignmentInExpressionsConfiguration ( )
153
+
150
154
/// Constructs a Configuration with all default values.
151
155
public init ( ) {
152
156
self . version = highestSupportedConfigurationVersion
@@ -208,6 +212,10 @@ public struct Configuration: Codable, Equatable {
208
212
?? FileScopedDeclarationPrivacyConfiguration ( )
209
213
self . indentSwitchCaseLabels
210
214
= try container. decodeIfPresent ( Bool . self, forKey: . indentSwitchCaseLabels) ?? false
215
+ self . noAssignmentInExpressions =
216
+ try container. decodeIfPresent (
217
+ NoAssignmentInExpressionsConfiguration . self, forKey: . noAssignmentInExpressions)
218
+ ?? NoAssignmentInExpressionsConfiguration ( )
211
219
212
220
// If the `rules` key is not present at all, default it to the built-in set
213
221
// so that the behavior is the same as if the configuration had been
@@ -238,6 +246,7 @@ public struct Configuration: Codable, Equatable {
238
246
spacesAroundRangeFormationOperators, forKey: . spacesAroundRangeFormationOperators)
239
247
try container. encode ( fileScopedDeclarationPrivacy, forKey: . fileScopedDeclarationPrivacy)
240
248
try container. encode ( indentSwitchCaseLabels, forKey: . indentSwitchCaseLabels)
249
+ try container. encode ( noAssignmentInExpressions, forKey: . noAssignmentInExpressions)
241
250
try container. encode ( rules, forKey: . rules)
242
251
}
243
252
@@ -287,3 +296,15 @@ public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
287
296
/// private access.
288
297
public var accessLevel : AccessLevel = . private
289
298
}
299
+
300
+ /// Configuration for the `NoAssignmentInExpressions` rule.
301
+ public struct NoAssignmentInExpressionsConfiguration : Codable , Equatable {
302
+ /// A list of function names where assignments are allowed to be embedded in expressions that are
303
+ /// passed as parameters to that function.
304
+ public var allowedFunctions : [ String ] = [
305
+ // Allow `XCTAssertNoThrow` because `XCTAssertNoThrow(x = try ...)` is clearer about intent than
306
+ // `x = try XCTUnwrap(try? ...)` or force-unwrapped if you need to use the value `x` later on
307
+ // in the test.
308
+ " XCTAssertNoThrow "
309
+ ]
310
+ }
0 commit comments