mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
1f44d56357
* `excludes_extensions` defaults to `true` to skip reporting violations for extensions with missing documentation comments. * `excludes_inherited_types` defaults to `true` to skip reporting violations for inherited declarations, like subclass overrides.
71 lines
2.8 KiB
Swift
71 lines
2.8 KiB
Swift
public struct MissingDocsRuleConfiguration: RuleConfiguration, Equatable {
|
|
private(set) var parameters = [RuleParameter<AccessControlLevel>]()
|
|
private(set) var excludesExtensions = true
|
|
private(set) var excludesInheritedTypes = true
|
|
|
|
public var consoleDescription: String {
|
|
let parametersDescription = parameters.group { $0.severity }.sorted { $0.key.rawValue < $1.key.rawValue }.map {
|
|
"\($0.rawValue): \($1.map { $0.value.description }.sorted(by: <).joined(separator: ", "))"
|
|
}.joined(separator: ", ")
|
|
|
|
if parametersDescription.isEmpty {
|
|
return [
|
|
"excludes_extensions: \(excludesExtensions)",
|
|
"excludes_inherited_types: \(excludesInheritedTypes)"
|
|
]
|
|
.joined(separator: ", ")
|
|
} else {
|
|
return [
|
|
parametersDescription,
|
|
"excludes_extensions: \(excludesExtensions)",
|
|
"excludes_inherited_types: \(excludesInheritedTypes)"
|
|
]
|
|
.joined(separator: ", ")
|
|
}
|
|
}
|
|
|
|
public mutating func apply(configuration: Any) throws {
|
|
guard let dict = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let shouldExcludeExtensions = dict["excludes_extensions"] as? Bool {
|
|
excludesExtensions = shouldExcludeExtensions
|
|
}
|
|
|
|
if let shouldExcludeInheritedTypes = dict["excludes_inherited_types"] as? Bool {
|
|
excludesExtensions = shouldExcludeInheritedTypes
|
|
}
|
|
|
|
var parameters: [RuleParameter<AccessControlLevel>] = []
|
|
|
|
for (key, value) in dict {
|
|
guard let severity = ViolationSeverity(rawValue: key) else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
if let array = [String].array(of: value) {
|
|
let rules: [RuleParameter<AccessControlLevel>] = try array
|
|
.map { val -> RuleParameter<AccessControlLevel> in
|
|
guard let acl = AccessControlLevel(description: val) else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
return RuleParameter<AccessControlLevel>(severity: severity, value: acl)
|
|
}
|
|
|
|
parameters.append(contentsOf: rules)
|
|
} else if let string = value as? String, let acl = AccessControlLevel(description: string) {
|
|
let rule = RuleParameter<AccessControlLevel>(severity: severity, value: acl)
|
|
|
|
parameters.append(rule)
|
|
}
|
|
}
|
|
|
|
guard parameters.count == parameters.map({ $0.value }).unique.count else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
|
|
self.parameters = parameters
|
|
}
|
|
}
|