forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring
xct_specific_matcher
with matchers (realm#4905)
So that either `one-argument-asserts` or `two-argument-asserts` or both can be enabled. The following configuration effectively reverts back to the rule behavior prior to realm#3858: ```yaml xct_specific_matcher: matchers: - two-argument-asserts ```
- Loading branch information
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Source/SwiftLintFramework/Rules/RuleConfigurations/XCTSpecificMatcherRuleConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
struct XCTSpecificMatcherRuleConfiguration: SeverityBasedRuleConfiguration, Equatable { | ||
private(set) var severityConfiguration = SeverityConfiguration(.warning) | ||
private(set) var matchers = Set(Matcher.allCases) | ||
|
||
enum Matcher: String, Hashable, CaseIterable { | ||
case oneArgumentAsserts = "one-argument-asserts" | ||
case twoArgumentAsserts = "two-argument-asserts" | ||
} | ||
|
||
private enum ConfigurationKey: String { | ||
case severity | ||
case matchers | ||
} | ||
|
||
var consoleDescription: String { | ||
return [ | ||
"severity: \(severityConfiguration.consoleDescription)", | ||
"\(ConfigurationKey.matchers): \(matchers.map(\.rawValue).sorted().joined(separator: ", "))" | ||
].joined(separator: ", ") | ||
} | ||
|
||
mutating func apply(configuration: Any) throws { | ||
guard let configuration = configuration as? [String: Any] else { | ||
throw ConfigurationError.unknownConfiguration | ||
} | ||
|
||
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String { | ||
try severityConfiguration.apply(configuration: severityString) | ||
} | ||
|
||
if let matchers = configuration[ConfigurationKey.matchers.rawValue] as? [String] { | ||
self.matchers = Set(matchers.compactMap(Matcher.init(rawValue:))) | ||
} | ||
} | ||
} |