mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
d305e03905
Current events have renewed the conversation in our community about the roles of terminology with racist connotations in our software. Many companies and developers are now taking appropriate steps to remove this terminology from their codebases and products. (e.g. [GitHub](https://twitter.com/natfriedman/status/1271253144442253312)) This small rule prevents the use of declarations that contain any of the terms: whitelist, blacklist, master, and slave. It may be appropriate to add more terms to this list now or in the future.
55 lines
1.8 KiB
Swift
55 lines
1.8 KiB
Swift
private enum ConfigurationKey: String {
|
|
case severity
|
|
case additionalTerms = "additional_terms"
|
|
case overrideTerms = "override_terms"
|
|
}
|
|
|
|
public struct InclusiveLanguageConfiguration: RuleConfiguration, Equatable {
|
|
public var severityConfiguration = SeverityConfiguration(.warning)
|
|
public var additionalTerms: Set<String>?
|
|
public var overrideTerms: Set<String>?
|
|
public var allTerms: Set<String>
|
|
|
|
public var consoleDescription: String {
|
|
severityConfiguration.consoleDescription
|
|
+ ", additional_terms: \(additionalTerms?.sorted() ?? [])"
|
|
+ ", override_terms: \(overrideTerms?.sorted() ?? [])"
|
|
}
|
|
|
|
public var severity: ViolationSeverity {
|
|
severityConfiguration.severity
|
|
}
|
|
|
|
private let defaultTerms: Set<String> = [
|
|
"whitelist",
|
|
"blacklist",
|
|
"master",
|
|
"slave"
|
|
]
|
|
|
|
public init() {
|
|
self.allTerms = defaultTerms
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let configuration = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] {
|
|
try severityConfiguration.apply(configuration: severityString)
|
|
}
|
|
|
|
additionalTerms = lowercasedSet(for: .additionalTerms, from: configuration)
|
|
overrideTerms = lowercasedSet(for: .overrideTerms, from: configuration)
|
|
|
|
allTerms = overrideTerms ?? defaultTerms
|
|
allTerms.formUnion(additionalTerms ?? [])
|
|
}
|
|
|
|
private func lowercasedSet(for key: ConfigurationKey, from config: [String: Any]) -> Set<String>? {
|
|
guard let list = config[key.rawValue] as? [String] else { return nil }
|
|
return Set(list.map { $0.lowercased() })
|
|
}
|
|
}
|