@@ -36,6 +36,7 @@ public struct Configuration: Codable, Equatable {
3636 case indentSwitchCaseLabels
3737 case rules
3838 case spacesAroundRangeFormationOperators
39+ case noAssignmentInExpressions
3940 }
4041
4142 /// The version of this configuration.
@@ -147,6 +148,9 @@ public struct Configuration: Codable, Equatable {
147148 /// `...` and `..<`.
148149 public var spacesAroundRangeFormationOperators = false
149150
151+ /// Contains exceptions for the `NoAssignmentInExpressions` rule.
152+ public var noAssignmentInExpressions = NoAssignmentInExpressionsConfiguration ( )
153+
150154 /// Constructs a Configuration with all default values.
151155 public init ( ) {
152156 self . version = highestSupportedConfigurationVersion
@@ -208,6 +212,10 @@ public struct Configuration: Codable, Equatable {
208212 ?? FileScopedDeclarationPrivacyConfiguration ( )
209213 self . indentSwitchCaseLabels
210214 = try container. decodeIfPresent ( Bool . self, forKey: . indentSwitchCaseLabels) ?? false
215+ self . noAssignmentInExpressions =
216+ try container. decodeIfPresent (
217+ NoAssignmentInExpressionsConfiguration . self, forKey: . noAssignmentInExpressions)
218+ ?? NoAssignmentInExpressionsConfiguration ( )
211219
212220 // If the `rules` key is not present at all, default it to the built-in set
213221 // so that the behavior is the same as if the configuration had been
@@ -238,6 +246,7 @@ public struct Configuration: Codable, Equatable {
238246 spacesAroundRangeFormationOperators, forKey: . spacesAroundRangeFormationOperators)
239247 try container. encode ( fileScopedDeclarationPrivacy, forKey: . fileScopedDeclarationPrivacy)
240248 try container. encode ( indentSwitchCaseLabels, forKey: . indentSwitchCaseLabels)
249+ try container. encode ( noAssignmentInExpressions, forKey: . noAssignmentInExpressions)
241250 try container. encode ( rules, forKey: . rules)
242251 }
243252
@@ -287,3 +296,15 @@ public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
287296 /// private access.
288297 public var accessLevel : AccessLevel = . private
289298}
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