Open ConfigurationError up to be used more broadly (#5005)
This commit is contained in:
parent
f4987071f0
commit
405113f793
|
@ -18,7 +18,7 @@ struct AttributesConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let attributesWithArgumentsAlwaysOnNewLine
|
if let attributesWithArgumentsAlwaysOnNewLine
|
||||||
|
|
|
@ -17,7 +17,7 @@ public struct BlanketDisableCommandConfiguration: SeverityBasedRuleConfiguration
|
||||||
|
|
||||||
public mutating func apply(configuration: Any) throws {
|
public mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct CollectionAlignmentConfiguration: SeverityBasedRuleConfiguration, Equatab
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
alignColons = configuration["align_colons"] as? Bool ?? false
|
alignColons = configuration["align_colons"] as? Bool ?? false
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct ColonConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
flexibleRightSpacing = configuration["flexible_right_spacing"] as? Bool == true
|
flexibleRightSpacing = configuration["flexible_right_spacing"] as? Bool == true
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct ComputedAccessorsOrderRuleConfiguration: SeverityBasedRuleConfiguration,
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let orderString = configuration["order"] as? String,
|
if let orderString = configuration["order"] as? String,
|
||||||
|
|
|
@ -8,7 +8,7 @@ struct ConditionalReturnsOnNewlineConfiguration: SeverityBasedRuleConfiguration,
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
ifOnly = configuration["if_only"] as? Bool ?? false
|
ifOnly = configuration["if_only"] as? Bool ?? false
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct CyclomaticComplexityConfiguration: RuleConfiguration, Equatable {
|
||||||
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
||||||
for (string, value) in configDict {
|
for (string, value) in configDict {
|
||||||
guard let key = ConfigurationKey(rawValue: string) else {
|
guard let key = ConfigurationKey(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
case (.error, let intValue as Int):
|
case (.error, let intValue as Int):
|
||||||
|
@ -65,11 +65,11 @@ struct CyclomaticComplexityConfiguration: RuleConfiguration, Equatable {
|
||||||
case (.ignoresCaseStatements, let boolValue as Bool):
|
case (.ignoresCaseStatements, let boolValue as Bool):
|
||||||
ignoresCaseStatements = boolValue
|
ignoresCaseStatements = boolValue
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
private static func parseVersion(string: String) throws -> (Int, Int, Int) {
|
private static func parseVersion(string: String) throws -> (Int, Int, Int) {
|
||||||
func parseNumber(_ string: String) throws -> Int {
|
func parseNumber(_ string: String) throws -> Int {
|
||||||
guard let number = Int(string) else {
|
guard let number = Int(string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
return number
|
return number
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
let parts = string.components(separatedBy: ".")
|
let parts = string.components(separatedBy: ".")
|
||||||
switch parts.count {
|
switch parts.count {
|
||||||
case 0:
|
case 0:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
case 1:
|
case 1:
|
||||||
return (try parseNumber(parts[0]), 0, 0)
|
return (try parseNumber(parts[0]), 0, 0)
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -128,7 +128,7 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
for (key, value) in configuration {
|
for (key, value) in configuration {
|
||||||
if key == "severity", let value = value as? String {
|
if key == "severity", let value = value as? String {
|
||||||
|
@ -136,7 +136,7 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
guard let target = targets[key] else {
|
guard let target = targets[key] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
try target.update(using: value)
|
try target.update(using: value)
|
||||||
if let extensionConfigurationKey = target.platform.appExtensionCounterpart?.configurationKey,
|
if let extensionConfigurationKey = target.platform.appExtensionCounterpart?.configurationKey,
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct DiscouragedDirectInitConfiguration: SeverityBasedRuleConfiguration, Equat
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct EmptyCountConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
||||||
|
|
|
@ -59,7 +59,7 @@ struct ExpiringTodoConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let approachingExpiryConfiguration = configurationDict["approaching_expiry_severity"] {
|
if let approachingExpiryConfiguration = configurationDict["approaching_expiry_severity"] {
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct ExplicitTypeInterfaceConfiguration: SeverityBasedRuleConfiguration, Equat
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
for (key, value) in configuration {
|
for (key, value) in configuration {
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
|
@ -36,7 +36,7 @@ struct ExplicitTypeInterfaceConfiguration: SeverityBasedRuleConfiguration, Equat
|
||||||
case ("allow_redundancy", let allowRedundancy as Bool):
|
case ("allow_redundancy", let allowRedundancy as Bool):
|
||||||
self.allowRedundancy = allowRedundancy
|
self.allowRedundancy = allowRedundancy
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ struct FileHeaderConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: String] else {
|
guard let configuration = configuration as? [String: String] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the created regexes if possible.
|
// Cache the created regexes if possible.
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct FileLengthRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
||||||
for (string, value) in configDict {
|
for (string, value) in configDict {
|
||||||
guard let key = ConfigurationKey(rawValue: string) else {
|
guard let key = ConfigurationKey(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
case (.error, let intValue as Int):
|
case (.error, let intValue as Int):
|
||||||
|
@ -37,11 +37,11 @@ struct FileLengthRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
case (.ignoreCommentOnlyLines, let boolValue as Bool):
|
case (.ignoreCommentOnlyLines, let boolValue as Bool):
|
||||||
ignoreCommentOnlyLines = boolValue
|
ignoreCommentOnlyLines = boolValue
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct FileNameConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityConfiguration = configurationDict["severity"] {
|
if let severityConfiguration = configurationDict["severity"] {
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct FileNameNoSpaceConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityConfiguration = configurationDict["severity"] {
|
if let severityConfiguration = configurationDict["severity"] {
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct FileTypesOrderConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
var customOrder = [[FileType]]()
|
var customOrder = [[FileType]]()
|
||||||
|
|
|
@ -8,7 +8,7 @@ struct ForWhereRuleConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
allowForAsFilter = configuration["allow_for_as_filter"] as? Bool ?? false
|
allowForAsFilter = configuration["allow_for_as_filter"] as? Bool ?? false
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct FunctionParameterCountConfiguration: RuleConfiguration, Equatable {
|
||||||
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
} else if let configDict = configuration as? [String: Any], configDict.isNotEmpty {
|
||||||
for (string, value) in configDict {
|
for (string, value) in configDict {
|
||||||
guard let key = ConfigurationKey(rawValue: string) else {
|
guard let key = ConfigurationKey(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
case (.error, let intValue as Int):
|
case (.error, let intValue as Int):
|
||||||
|
@ -37,11 +37,11 @@ struct FunctionParameterCountConfiguration: RuleConfiguration, Equatable {
|
||||||
case (.ignoresDefaultParameters, let boolValue as Bool):
|
case (.ignoresDefaultParameters, let boolValue as Bool):
|
||||||
ignoresDefaultParameters = boolValue
|
ignoresDefaultParameters = boolValue
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,13 @@ struct ImplicitReturnConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let includedKinds = configuration["included"] as? [String] {
|
if let includedKinds = configuration["included"] as? [String] {
|
||||||
self.includedKinds = try Set(includedKinds.map {
|
self.includedKinds = try Set(includedKinds.map {
|
||||||
guard let kind = ReturnKind(rawValue: $0) else {
|
guard let kind = ReturnKind(rawValue: $0) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
return kind
|
return kind
|
||||||
|
|
|
@ -8,7 +8,7 @@ enum ImplicitlyUnwrappedOptionalModeConfiguration: String {
|
||||||
let value = Self(rawValue: string) {
|
let value = Self(rawValue: string) {
|
||||||
self = value
|
self = value
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ struct ImplicitlyUnwrappedOptionalConfiguration: SeverityBasedRuleConfiguration,
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let modeString = configuration["mode"] {
|
if let modeString = configuration["mode"] {
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct InclusiveLanguageConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration[ConfigurationKey.severity.rawValue] {
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] {
|
||||||
|
|
|
@ -29,7 +29,7 @@ struct IndentationWidthConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let config = configurationDict["severity"] {
|
if let config = configurationDict["severity"] {
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct LineLengthConfiguration: RuleConfiguration, Equatable {
|
||||||
///
|
///
|
||||||
/// - throws: Throws if the configuration value isn't properly formatted.
|
/// - throws: Throws if the configuration value isn't properly formatted.
|
||||||
private mutating func applyDictionary(configuration: Any) throws {
|
private mutating func applyDictionary(configuration: Any) throws {
|
||||||
let error = ConfigurationError.unknownConfiguration
|
let error = Issue.unknownConfiguration
|
||||||
guard let configDict = configuration as? [String: Any],
|
guard let configDict = configuration as? [String: Any],
|
||||||
configDict.isNotEmpty else {
|
configDict.isNotEmpty else {
|
||||||
throw error
|
throw error
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct MissingDocsRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let dict = configuration as? [String: Any] else {
|
guard let dict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let shouldExcludeExtensions = dict["excludes_extensions"] as? Bool {
|
if let shouldExcludeExtensions = dict["excludes_extensions"] as? Bool {
|
||||||
|
@ -64,7 +64,7 @@ struct MissingDocsRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
let rules: [RuleParameter<AccessControlLevel>] = try array
|
let rules: [RuleParameter<AccessControlLevel>] = try array
|
||||||
.map { val -> RuleParameter<AccessControlLevel> in
|
.map { val -> RuleParameter<AccessControlLevel> in
|
||||||
guard let acl = AccessControlLevel(description: val) else {
|
guard let acl = AccessControlLevel(description: val) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
return RuleParameter<AccessControlLevel>(severity: severity, value: acl)
|
return RuleParameter<AccessControlLevel>(severity: severity, value: acl)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ struct MissingDocsRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
guard parameters.count == parameters.map({ $0.value }).unique.count else {
|
guard parameters.count == parameters.map({ $0.value }).unique.count else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters.isNotEmpty ? parameters : nil
|
return parameters.isNotEmpty ? parameters : nil
|
||||||
|
|
|
@ -19,14 +19,14 @@ struct ModifierOrderConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let preferredModifierOrder = configuration["preferred_modifier_order"] as? [String] {
|
if let preferredModifierOrder = configuration["preferred_modifier_order"] as? [String] {
|
||||||
self.preferredModifierOrder = try preferredModifierOrder.map {
|
self.preferredModifierOrder = try preferredModifierOrder.map {
|
||||||
guard let modifierGroup = SwiftDeclarationAttributeKind.ModifierGroup(rawValue: $0),
|
guard let modifierGroup = SwiftDeclarationAttributeKind.ModifierGroup(rawValue: $0),
|
||||||
modifierGroup != .atPrefixed else {
|
modifierGroup != .atPrefixed else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
return modifierGroup
|
return modifierGroup
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct MultilineArgumentsConfiguration: RuleConfiguration, SeverityBasedRuleConf
|
||||||
guard
|
guard
|
||||||
let string = (value as? String)?.lowercased(),
|
let string = (value as? String)?.lowercased(),
|
||||||
let value = Self(rawValue: string) else {
|
let value = Self(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
self = value
|
self = value
|
||||||
|
@ -33,7 +33,7 @@ struct MultilineArgumentsConfiguration: RuleConfiguration, SeverityBasedRuleConf
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
let error = ConfigurationError.unknownConfiguration
|
let error = Issue.unknownConfiguration
|
||||||
|
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw error
|
throw error
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct MultilineParametersConfiguration: SeverityBasedRuleConfiguration, Equatab
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
allowsSingleLine = configuration["allows_single_line"] as? Bool ?? true
|
allowsSingleLine = configuration["allows_single_line"] as? Bool ?? true
|
||||||
|
|
|
@ -48,7 +48,7 @@ struct NameConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let minLengthConfiguration = configurationDict["min_length"] {
|
if let minLengthConfiguration = configurationDict["min_length"] {
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct NestingConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let typeLevelConfiguration = configurationDict["type_level"] {
|
if let typeLevelConfiguration = configurationDict["type_level"] {
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct NumberSeparatorConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let minimumLength = configuration["minimum_length"] as? Int {
|
if let minimumLength = configuration["minimum_length"] as? Int {
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct ObjectLiteralConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
imageLiteral = configuration["image_literal"] as? Bool ?? true
|
imageLiteral = configuration["image_literal"] as? Bool ?? true
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct OpeningBraceConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
||||||
|
|
|
@ -13,7 +13,7 @@ struct OperatorUsageWhitespaceConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
linesLookAround = configuration["lines_look_around"] as? Int ?? 2
|
linesLookAround = configuration["lines_look_around"] as? Int ?? 2
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct OverriddenSuperCallConfiguration: SeverityBasedRuleConfiguration, Equatab
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct PrefixedConstantRuleConfiguration: SeverityBasedRuleConfiguration, Equata
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
onlyPrivateMembers = (configuration["only_private"] as? Bool == true)
|
onlyPrivateMembers = (configuration["only_private"] as? Bool == true)
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct PrivateOutletRuleConfiguration: SeverityBasedRuleConfiguration, Equatable
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
allowPrivateSet = (configuration["allow_private_set"] as? Bool == true)
|
allowPrivateSet = (configuration["allow_private_set"] as? Bool == true)
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct PrivateOverFilePrivateRuleConfiguration: SeverityBasedRuleConfiguration,
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct PrivateUnitTestConfiguration: SeverityBasedRuleConfiguration, Equatable,
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
if let regexString = configurationDict["regex"] as? String {
|
if let regexString = configurationDict["regex"] as? String {
|
||||||
regex = try .cached(pattern: regexString)
|
regex = try .cached(pattern: regexString)
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct ProhibitedSuperConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct RequiredEnumCaseRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let config = configuration as? [String: [String: String]] else {
|
guard let config = configuration as? [String: [String: String]] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
register(protocols: config)
|
register(protocols: config)
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct SelfBindingConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
||||||
|
|
|
@ -7,7 +7,7 @@ enum StatementModeConfiguration: String {
|
||||||
let value = Self(rawValue: string) {
|
let value = Self(rawValue: string) {
|
||||||
self = value
|
self = value
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ struct StatementConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
if let statementModeConfiguration = configurationDict["statement_mode"] {
|
if let statementModeConfiguration = configurationDict["statement_mode"] {
|
||||||
try statementMode = StatementModeConfiguration(value: statementModeConfiguration)
|
try statementMode = StatementModeConfiguration(value: statementModeConfiguration)
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct SwitchCaseAlignmentConfiguration: SeverityBasedRuleConfiguration, Equatab
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
indentedCases = configuration["indented_cases"] as? Bool ?? false
|
indentedCases = configuration["indented_cases"] as? Bool ?? false
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct TestCaseAccessibilityConfiguration: SeverityBasedRuleConfiguration, Equat
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -13,7 +13,7 @@ struct TrailingClosureConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
onlySingleMutedParameter = (configuration["only_single_muted_parameter"] as? Bool == true)
|
onlySingleMutedParameter = (configuration["only_single_muted_parameter"] as? Bool == true)
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct TrailingCommaConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
mandatoryComma = (configuration["mandatory_comma"] as? Bool == true)
|
mandatoryComma = (configuration["mandatory_comma"] as? Bool == true)
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct TrailingWhitespaceConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoresEmptyLines = (configuration["ignores_empty_lines"] as? Bool == true)
|
ignoresEmptyLines = (configuration["ignores_empty_lines"] as? Bool == true)
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct TypeContentsOrderConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
var customOrder = [[TypeContent]]()
|
var customOrder = [[TypeContent]]()
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct TypeNameRuleConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
try nameConfiguration.apply(configuration: configuration)
|
try nameConfiguration.apply(configuration: configuration)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct UnitTestRuleConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration["severity"] as? String {
|
if let severityString = configuration["severity"] as? String {
|
||||||
|
|
|
@ -23,12 +23,12 @@ struct UnusedDeclarationConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configDict = configuration as? [String: Any], configDict.isNotEmpty else {
|
guard let configDict = configuration as? [String: Any], configDict.isNotEmpty else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
for (string, value) in configDict {
|
for (string, value) in configDict {
|
||||||
guard let key = ConfigurationKey(rawValue: string) else {
|
guard let key = ConfigurationKey(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
case (.severity, let stringValue as String):
|
case (.severity, let stringValue as String):
|
||||||
|
@ -39,10 +39,10 @@ struct UnusedDeclarationConfiguration: RuleConfiguration, Equatable {
|
||||||
if let usrs = [String].array(of: value) {
|
if let usrs = [String].array(of: value) {
|
||||||
relatedUSRsToSkip.formUnion(usrs)
|
relatedUSRsToSkip.formUnion(usrs)
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct TransitiveModuleConfiguration: Equatable {
|
||||||
let importedModule = configurationDict["module"] as? String,
|
let importedModule = configurationDict["module"] as? String,
|
||||||
let transitivelyImportedModules = configurationDict["allowed_transitive_imports"] as? [String]
|
let transitivelyImportedModules = configurationDict["allowed_transitive_imports"] as? [String]
|
||||||
else {
|
else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
self.importedModule = importedModule
|
self.importedModule = importedModule
|
||||||
self.transitivelyImportedModules = transitivelyImportedModules
|
self.transitivelyImportedModules = transitivelyImportedModules
|
||||||
|
@ -46,7 +46,7 @@ struct UnusedImportConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityConfiguration = configurationDict["severity"] {
|
if let severityConfiguration = configurationDict["severity"] {
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct UnusedOptionalBindingConfiguration: SeverityBasedRuleConfiguration, Equat
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ignoreOptionalTry = configuration["ignore_optional_try"] as? Bool {
|
if let ignoreOptionalTry = configuration["ignore_optional_try"] as? Bool {
|
||||||
|
|
|
@ -15,12 +15,12 @@ struct VerticalWhitespaceClosingBracesConfiguration: RuleConfiguration, Equatabl
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
for (string, value) in configuration {
|
for (string, value) in configuration {
|
||||||
guard let key = ConfigurationKey(rawValue: string) else {
|
guard let key = ConfigurationKey(rawValue: string) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (key, value) {
|
switch (key, value) {
|
||||||
|
@ -29,7 +29,7 @@ struct VerticalWhitespaceClosingBracesConfiguration: RuleConfiguration, Equatabl
|
||||||
case (.onlyEnforceBeforeTrivialLines, let boolValue as Bool):
|
case (.onlyEnforceBeforeTrivialLines, let boolValue as Bool):
|
||||||
onlyEnforceBeforeTrivialLines = boolValue
|
onlyEnforceBeforeTrivialLines = boolValue
|
||||||
default:
|
default:
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct VerticalWhitespaceConfiguration: RuleConfiguration, Equatable {
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let maxEmptyLines = configuration["max_empty_lines"] as? Int {
|
if let maxEmptyLines = configuration["max_empty_lines"] as? Int {
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct XCTSpecificMatcherRuleConfiguration: SeverityBasedRuleConfiguration, Equa
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configuration = configuration as? [String: Any] else {
|
guard let configuration = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
if let severityString = configuration[ConfigurationKey.severity.rawValue] as? String {
|
||||||
|
|
|
@ -120,7 +120,7 @@ public extension Configuration {
|
||||||
// Local vertices are allowed to have local / remote references
|
// Local vertices are allowed to have local / remote references
|
||||||
// Remote vertices are only allowed to have remote references
|
// Remote vertices are only allowed to have remote references
|
||||||
if vertix.originatesFromRemote && !referencedVertix.originatesFromRemote {
|
if vertix.originatesFromRemote && !referencedVertix.originatesFromRemote {
|
||||||
throw ConfigurationError.generic("Remote configs are not allowed to reference local configs.")
|
throw Issue.genericWarning("Remote configs are not allowed to reference local configs.")
|
||||||
} else {
|
} else {
|
||||||
let existingVertix = findPossiblyExistingVertix(sameAs: referencedVertix)
|
let existingVertix = findPossiblyExistingVertix(sameAs: referencedVertix)
|
||||||
let existingVertixCopy = existingVertix.map { $0.copy(withNewRootDirectory: rootDirectory) }
|
let existingVertixCopy = existingVertix.map { $0.copy(withNewRootDirectory: rootDirectory) }
|
||||||
|
@ -169,7 +169,7 @@ public extension Configuration {
|
||||||
// Please note that the equality check (`==`), not the identity check (`===`) is used
|
// Please note that the equality check (`==`), not the identity check (`===`) is used
|
||||||
let children = edges.filter { $0.parent == stack.last }.map { $0.child! }
|
let children = edges.filter { $0.parent == stack.last }.map { $0.child! }
|
||||||
if stack.contains(where: children.contains) {
|
if stack.contains(where: children.contains) {
|
||||||
throw ConfigurationError.generic("There's a cycle of child / parent config references. "
|
throw Issue.genericWarning("There's a cycle of child / parent config references. "
|
||||||
+ "Please check the hierarchy of configuration files passed via the command line "
|
+ "Please check the hierarchy of configuration files passed via the command line "
|
||||||
+ "and the childConfig / parentConfig entries within them.")
|
+ "and the childConfig / parentConfig entries within them.")
|
||||||
}
|
}
|
||||||
|
@ -180,13 +180,13 @@ public extension Configuration {
|
||||||
|
|
||||||
// Detect ambiguities
|
// Detect ambiguities
|
||||||
if (edges.contains { edge in edges.filter { $0.parent == edge.parent }.count > 1 }) {
|
if (edges.contains { edge in edges.filter { $0.parent == edge.parent }.count > 1 }) {
|
||||||
throw ConfigurationError.generic("There's an ambiguity in the child / parent configuration tree: "
|
throw Issue.genericWarning("There's an ambiguity in the child / parent configuration tree: "
|
||||||
+ "More than one parent is declared for a specific configuration, "
|
+ "More than one parent is declared for a specific configuration, "
|
||||||
+ "where there should only be exactly one.")
|
+ "where there should only be exactly one.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edges.contains { edge in edges.filter { $0.child == edge.child }.count > 1 }) {
|
if (edges.contains { edge in edges.filter { $0.child == edge.child }.count > 1 }) {
|
||||||
throw ConfigurationError.generic("There's an ambiguity in the child / parent configuration tree: "
|
throw Issue.genericWarning("There's an ambiguity in the child / parent configuration tree: "
|
||||||
+ "More than one child is declared for a specific configuration, "
|
+ "More than one child is declared for a specific configuration, "
|
||||||
+ "where there should only be exactly one.")
|
+ "where there should only be exactly one.")
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public extension Configuration {
|
||||||
let startingVertix = (vertices.first { vertix in !edges.contains { $0.child == vertix } })
|
let startingVertix = (vertices.first { vertix in !edges.contains { $0.child == vertix } })
|
||||||
else {
|
else {
|
||||||
guard vertices.isEmpty else {
|
guard vertices.isEmpty else {
|
||||||
throw ConfigurationError.generic("Unknown Configuration Error")
|
throw Issue.genericWarning("Unknown Configuration Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
@ -206,7 +206,7 @@ public extension Configuration {
|
||||||
while let vertix = (edges.first { $0.parent == verticesToMerge.last }?.child) {
|
while let vertix = (edges.first { $0.parent == verticesToMerge.last }?.child) {
|
||||||
guard !verticesToMerge.contains(vertix) else {
|
guard !verticesToMerge.contains(vertix) else {
|
||||||
// This shouldn't happen on a cycle free graph but let's safeguard
|
// This shouldn't happen on a cycle free graph but let's safeguard
|
||||||
throw ConfigurationError.generic("Unknown Configuration Error")
|
throw Issue.genericWarning("Unknown Configuration Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
verticesToMerge.append(vertix)
|
verticesToMerge.append(vertix)
|
||||||
|
|
|
@ -74,8 +74,8 @@ internal extension Configuration.FileGraph {
|
||||||
private func read(at path: String) throws -> String {
|
private func read(at path: String) throws -> String {
|
||||||
guard !path.isEmpty && FileManager.default.fileExists(atPath: path) else {
|
guard !path.isEmpty && FileManager.default.fileExists(atPath: path) else {
|
||||||
throw isInitialVertix ?
|
throw isInitialVertix ?
|
||||||
ConfigurationError.initialFileNotFound(path: path) :
|
Issue.initialFileNotFound(path: path) :
|
||||||
ConfigurationError.generic("File \(path) can't be found.")
|
Issue.genericWarning("File \(path) can't be found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return try String(contentsOfFile: path, encoding: .utf8)
|
return try String(contentsOfFile: path, encoding: .utf8)
|
||||||
|
|
|
@ -60,7 +60,7 @@ extension Configuration {
|
||||||
} catch let RuleListError.duplicatedConfigurations(ruleType) {
|
} catch let RuleListError.duplicatedConfigurations(ruleType) {
|
||||||
let aliases = ruleType.description.deprecatedAliases.map { "'\($0)'" }.joined(separator: ", ")
|
let aliases = ruleType.description.deprecatedAliases.map { "'\($0)'" }.joined(separator: ", ")
|
||||||
let identifier = ruleType.description.identifier
|
let identifier = ruleType.description.identifier
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"Multiple configurations found for '\(identifier)'. Check for any aliases: \(aliases)."
|
"Multiple configurations found for '\(identifier)'. Check for any aliases: \(aliases)."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
|
|
||||||
// Handle wrong url format
|
// Handle wrong url format
|
||||||
guard let url = URL(string: urlString) else {
|
guard let url = URL(string: urlString) else {
|
||||||
throw ConfigurationError.generic("Invalid configuration entry: \"\(urlString)\" isn't a valid url.")
|
throw Issue.genericWarning("Invalid configuration entry: \"\(urlString)\" isn't a valid url.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from url
|
// Load from url
|
||||||
|
@ -126,7 +126,7 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
self = .existing(path: cachedFilePath)
|
self = .existing(path: cachedFilePath)
|
||||||
return cachedFilePath
|
return cachedFilePath
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"No internet connectivity: Unable to load remote config from \"\(urlString)\". "
|
"No internet connectivity: Unable to load remote config from \"\(urlString)\". "
|
||||||
+ "Also didn't found cached version to fallback to."
|
+ "Also didn't found cached version to fallback to."
|
||||||
)
|
)
|
||||||
|
@ -155,12 +155,12 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
return cachedFilePath
|
return cachedFilePath
|
||||||
} else {
|
} else {
|
||||||
if taskDone {
|
if taskDone {
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"Unable to load remote config from \"\(urlString)\". "
|
"Unable to load remote config from \"\(urlString)\". "
|
||||||
+ "Also didn't found cached version to fallback to."
|
+ "Also didn't found cached version to fallback to."
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"Timeout (\(timeout) sec): Unable to load remote config from \"\(urlString)\". "
|
"Timeout (\(timeout) sec): Unable to load remote config from \"\(urlString)\". "
|
||||||
+ "Also didn't found cached version to fallback to."
|
+ "Also didn't found cached version to fallback to."
|
||||||
)
|
)
|
||||||
|
@ -176,7 +176,7 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
self = .existing(path: cachedFilePath)
|
self = .existing(path: cachedFilePath)
|
||||||
return cachedFilePath
|
return cachedFilePath
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"Unable to cache remote config from \"\(urlString)\". Also didn't found cached version to fallback to."
|
"Unable to cache remote config from \"\(urlString)\". Also didn't found cached version to fallback to."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
contents: Data(newGitignoreAppendix.utf8),
|
contents: Data(newGitignoreAppendix.utf8),
|
||||||
attributes: [:]
|
attributes: [:]
|
||||||
) else {
|
) else {
|
||||||
throw ConfigurationError.generic("Issue maintaining remote config cache.")
|
throw Issue.genericWarning("Issue maintaining remote config cache.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var contents = try String(contentsOfFile: Configuration.FileGraph.FilePath.gitignorePath, encoding: .utf8)
|
var contents = try String(contentsOfFile: Configuration.FileGraph.FilePath.gitignorePath, encoding: .utf8)
|
||||||
|
|
|
@ -50,7 +50,7 @@ public extension Configuration {
|
||||||
self = .allEnabled
|
self = .allEnabled
|
||||||
} else if onlyRules.isNotEmpty {
|
} else if onlyRules.isNotEmpty {
|
||||||
if disabledRules.isNotEmpty || optInRules.isNotEmpty {
|
if disabledRules.isNotEmpty || optInRules.isNotEmpty {
|
||||||
throw ConfigurationError.generic(
|
throw Issue.genericWarning(
|
||||||
"'\(Configuration.Key.disabledRules.rawValue)' or " +
|
"'\(Configuration.Key.disabledRules.rawValue)' or " +
|
||||||
"'\(Configuration.Key.optInRules.rawValue)' cannot be used in combination " +
|
"'\(Configuration.Key.optInRules.rawValue)' cannot be used in combination " +
|
||||||
"with '\(Configuration.Key.onlyRules.rawValue)'"
|
"with '\(Configuration.Key.onlyRules.rawValue)'"
|
||||||
|
|
|
@ -4,7 +4,7 @@ public extension SyntaxKind {
|
||||||
init(shortName: Swift.String) throws {
|
init(shortName: Swift.String) throws {
|
||||||
let prefix = "source.lang.swift.syntaxtype."
|
let prefix = "source.lang.swift.syntaxtype."
|
||||||
guard let kind = SyntaxKind(rawValue: prefix + shortName.lowercased()) else {
|
guard let kind = SyntaxKind(rawValue: prefix + shortName.lowercased()) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
self = kind
|
self = kind
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ private enum FileGraphInitializationResult {
|
||||||
|
|
||||||
init(error: Error, hasCustomConfigurationFiles: Bool) {
|
init(error: Error, hasCustomConfigurationFiles: Bool) {
|
||||||
switch error {
|
switch error {
|
||||||
case let ConfigurationError.initialFileNotFound(path):
|
case let Issue.initialFileNotFound(path):
|
||||||
if hasCustomConfigurationFiles {
|
if hasCustomConfigurationFiles {
|
||||||
self = .error(message: "SwiftLint Configuration Error: Could not read file at path: \(path)")
|
self = .error(message: "SwiftLint Configuration Error: Could not read file at path: \(path)")
|
||||||
} else {
|
} else {
|
||||||
|
@ -270,9 +270,9 @@ private enum FileGraphInitializationResult {
|
||||||
// -> don't handle as error
|
// -> don't handle as error
|
||||||
self = .initialImplicitFileNotFound
|
self = .initialImplicitFileNotFound
|
||||||
}
|
}
|
||||||
case let ConfigurationError.generic(message):
|
case let Issue.genericWarning(message):
|
||||||
self = .error(message: "SwiftLint Configuration Error: \(message)")
|
self = .error(message: "SwiftLint Configuration Error: \(message)")
|
||||||
case let YamlParserError.yamlParsing(message):
|
case let Issue.yamlParsing(message):
|
||||||
self = .error(message: "YML Parsing Error: \(message)")
|
self = .error(message: "YML Parsing Error: \(message)")
|
||||||
default:
|
default:
|
||||||
self = .error(message: error.localizedDescription)
|
self = .error(message: error.localizedDescription)
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
/// All possible configuration errors.
|
|
||||||
public enum ConfigurationError: Error, Equatable {
|
|
||||||
/// The configuration didn't match internal expectations.
|
|
||||||
case unknownConfiguration
|
|
||||||
|
|
||||||
/// The configuration had both `match_kind` and `excluded_match_kind` parameters.
|
|
||||||
case ambiguousMatchKindParameters
|
|
||||||
|
|
||||||
/// A generic configuration error specified by a string.
|
|
||||||
case generic(String)
|
|
||||||
|
|
||||||
/// The initial configuration file was not found.
|
|
||||||
case initialFileNotFound(path: String)
|
|
||||||
}
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// All possible SwiftLint issues which are printed as warnings by default.
|
||||||
|
public enum Issue: LocalizedError, Equatable {
|
||||||
|
/// The configuration didn't match internal expectations.
|
||||||
|
case unknownConfiguration
|
||||||
|
|
||||||
|
/// A generic warning specified by a string.
|
||||||
|
case genericWarning(String)
|
||||||
|
|
||||||
|
/// A deprecation warning for a rule.
|
||||||
|
case deprecation(ruleID: String)
|
||||||
|
|
||||||
|
/// The initial configuration file was not found.
|
||||||
|
case initialFileNotFound(path: String)
|
||||||
|
|
||||||
|
/// An error that occurred when parsing YAML.
|
||||||
|
case yamlParsing(String)
|
||||||
|
|
||||||
|
/// The issues description which is ready to be printed to the console.
|
||||||
|
var errorDescription: String {
|
||||||
|
switch self {
|
||||||
|
case .genericWarning:
|
||||||
|
return "warning: \(message)"
|
||||||
|
default:
|
||||||
|
return Self.genericWarning(message).errorDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var message: String {
|
||||||
|
switch self {
|
||||||
|
case .unknownConfiguration:
|
||||||
|
return "Invalid configuration. Falling back to default."
|
||||||
|
case .genericWarning(let message):
|
||||||
|
return "\(message)"
|
||||||
|
case .deprecation(let ruleID):
|
||||||
|
return """
|
||||||
|
The `\(ruleID)` rule is now deprecated and will be \
|
||||||
|
completely removed in a future release.
|
||||||
|
"""
|
||||||
|
case .initialFileNotFound(let path):
|
||||||
|
return "Could not read file at path \(path)."
|
||||||
|
case .yamlParsing(let message):
|
||||||
|
return "Cannot parse YAML file: \(message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ public struct SeverityConfiguration: SeverityBasedRuleConfiguration, Equatable {
|
||||||
let configDict = configuration as? [String: Any]
|
let configDict = configuration as? [String: Any]
|
||||||
guard let severityString: String = configString ?? configDict?["severity"] as? String,
|
guard let severityString: String = configString ?? configDict?["severity"] as? String,
|
||||||
let severity = ViolationSeverity(rawValue: severityString.lowercased()) else {
|
let severity = ViolationSeverity(rawValue: severityString.lowercased()) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
self.severity = severity
|
self.severity = severity
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
// MARK: - YamlParsingError
|
|
||||||
|
|
||||||
internal enum YamlParserError: Error, Equatable {
|
|
||||||
case yamlParsing(String)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - YamlParser
|
// MARK: - YamlParser
|
||||||
|
|
||||||
/// An interface for parsing YAML.
|
/// An interface for parsing YAML.
|
||||||
|
@ -25,7 +19,7 @@ public struct YamlParser {
|
||||||
return try Yams.load(yaml: yaml, .default,
|
return try Yams.load(yaml: yaml, .default,
|
||||||
.swiftlintConstructor(env: env)) as? [String: Any] ?? [:]
|
.swiftlintConstructor(env: env)) as? [String: Any] ?? [:]
|
||||||
} catch {
|
} catch {
|
||||||
throw YamlParserError.yamlParsing("\(error)")
|
throw Issue.yamlParsing("\(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, Hashable, Cach
|
||||||
public mutating func apply(configuration: Any) throws {
|
public mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any],
|
guard let configurationDict = configuration as? [String: Any],
|
||||||
let regexString = configurationDict["regex"] as? String else {
|
let regexString = configurationDict["regex"] as? String else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
regex = try .cached(pattern: regexString)
|
regex = try .cached(pattern: regexString)
|
||||||
|
@ -93,7 +93,7 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, Hashable, Cach
|
||||||
}
|
}
|
||||||
if let captureGroup = configurationDict["capture_group"] as? Int {
|
if let captureGroup = configurationDict["capture_group"] as? Int {
|
||||||
guard (0 ... regex.numberOfCaptureGroups).contains(captureGroup) else {
|
guard (0 ... regex.numberOfCaptureGroups).contains(captureGroup) else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
self.captureGroup = captureGroup
|
self.captureGroup = captureGroup
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,9 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, Hashable, Cach
|
||||||
case (nil, nil):
|
case (nil, nil):
|
||||||
return .init()
|
return .init()
|
||||||
case (.some, .some):
|
case (.some, .some):
|
||||||
throw ConfigurationError.ambiguousMatchKindParameters
|
throw Issue.genericWarning(
|
||||||
|
"The configuration keys 'match_kinds' and 'excluded_match_kinds' cannot appear at the same time."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public struct SeverityLevelsConfiguration: RuleConfiguration, Equatable {
|
||||||
warning = (configDict["warning"] as? Int) ?? warning
|
warning = (configDict["warning"] as? Int) ?? warning
|
||||||
error = configDict["error"] as? Int
|
error = configDict["error"] as? Int
|
||||||
} else {
|
} else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct CustomRulesConfiguration: RuleConfiguration, Equatable, CacheDescriptionP
|
||||||
|
|
||||||
mutating func apply(configuration: Any) throws {
|
mutating func apply(configuration: Any) throws {
|
||||||
guard let configurationDict = configuration as? [String: Any] else {
|
guard let configurationDict = configuration as? [String: Any] else {
|
||||||
throw ConfigurationError.unknownConfiguration
|
throw Issue.unknownConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
for (key, value) in configurationDict {
|
for (key, value) in configurationDict {
|
||||||
|
|
|
@ -60,7 +60,7 @@ class CustomRulesTests: SwiftLintTestCase {
|
||||||
func testCustomRuleConfigurationThrows() {
|
func testCustomRuleConfigurationThrows() {
|
||||||
let config = 17
|
let config = 17
|
||||||
var customRulesConfig = CustomRulesConfiguration()
|
var customRulesConfig = CustomRulesConfiguration()
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try customRulesConfig.apply(configuration: config)
|
try customRulesConfig.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,10 @@ class CustomRulesTests: SwiftLintTestCase {
|
||||||
]
|
]
|
||||||
|
|
||||||
var configuration = RegexConfiguration(identifier: "my_custom_rule")
|
var configuration = RegexConfiguration(identifier: "my_custom_rule")
|
||||||
checkError(ConfigurationError.ambiguousMatchKindParameters) {
|
let expectedError = Issue.genericWarning(
|
||||||
|
"The configuration keys 'match_kinds' and 'excluded_match_kinds' cannot appear at the same time."
|
||||||
|
)
|
||||||
|
checkError(expectedError) {
|
||||||
try configuration.apply(configuration: configDict)
|
try configuration.apply(configuration: configDict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class CyclomaticComplexityConfigurationTests: SwiftLintTestCase {
|
||||||
|
|
||||||
for badConfig in badConfigs {
|
for badConfig in badConfigs {
|
||||||
var configuration = CyclomaticComplexityConfiguration(warning: 100, error: 150)
|
var configuration = CyclomaticComplexityConfiguration(warning: 100, error: 150)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: badConfig)
|
try configuration.apply(configuration: badConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ class DeploymentTargetConfigurationTests: SwiftLintTestCase {
|
||||||
|
|
||||||
for badConfig in badConfigs {
|
for badConfig in badConfigs {
|
||||||
var configuration = DeploymentTargetConfiguration()
|
var configuration = DeploymentTargetConfiguration()
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: badConfig)
|
try configuration.apply(configuration: badConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,21 +20,21 @@ class ExplicitTypeInterfaceConfigurationTests: SwiftLintTestCase {
|
||||||
|
|
||||||
func testInvalidKeyInCustomConfiguration() {
|
func testInvalidKeyInCustomConfiguration() {
|
||||||
var config = ExplicitTypeInterfaceConfiguration()
|
var config = ExplicitTypeInterfaceConfiguration()
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try config.apply(configuration: ["invalidKey": "error"])
|
try config.apply(configuration: ["invalidKey": "error"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInvalidTypeOfCustomConfiguration() {
|
func testInvalidTypeOfCustomConfiguration() {
|
||||||
var config = ExplicitTypeInterfaceConfiguration()
|
var config = ExplicitTypeInterfaceConfiguration()
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try config.apply(configuration: "invalidKey")
|
try config.apply(configuration: "invalidKey")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInvalidTypeOfValueInCustomConfiguration() {
|
func testInvalidTypeOfValueInCustomConfiguration() {
|
||||||
var config = ExplicitTypeInterfaceConfiguration()
|
var config = ExplicitTypeInterfaceConfiguration()
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try config.apply(configuration: ["severity": 1])
|
try config.apply(configuration: ["severity": 1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ImplicitReturnConfigurationTests: SwiftLintTestCase {
|
||||||
var configuration = ImplicitReturnConfiguration()
|
var configuration = ImplicitReturnConfiguration()
|
||||||
let config = ["included": ["foreach"]] as [String: Any]
|
let config = ["included": ["foreach"]] as [String: Any]
|
||||||
|
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: config)
|
try configuration.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ImplicitlyUnwrappedOptionalConfigurationTests: SwiftLintTestCase {
|
||||||
severityConfiguration: SeverityConfiguration(.warning)
|
severityConfiguration: SeverityConfiguration(.warning)
|
||||||
)
|
)
|
||||||
|
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: badConfig)
|
try configuration.apply(configuration: badConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ class LineLengthConfigurationTests: SwiftLintTestCase {
|
||||||
func testLineLengthConfigurationThrowsOnBadConfig() {
|
func testLineLengthConfigurationThrowsOnBadConfig() {
|
||||||
let config = "unknown"
|
let config = "unknown"
|
||||||
var configuration = LineLengthConfiguration(warning: 100, error: 150)
|
var configuration = LineLengthConfiguration(warning: 100, error: 150)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: config)
|
try configuration.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class LineLengthConfigurationTests: SwiftLintTestCase {
|
||||||
|
|
||||||
for badConfig in badConfigs {
|
for badConfig in badConfigs {
|
||||||
var configuration = LineLengthConfiguration(warning: 100, error: 150)
|
var configuration = LineLengthConfiguration(warning: 100, error: 150)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: badConfig)
|
try configuration.apply(configuration: badConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class NameConfigurationTests: SwiftLintTestCase {
|
||||||
minLengthError: 0,
|
minLengthError: 0,
|
||||||
maxLengthWarning: 0,
|
maxLengthWarning: 0,
|
||||||
maxLengthError: 0)
|
maxLengthError: 0)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try nameConfig.apply(configuration: config)
|
try nameConfig.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
typeLevelError: nil,
|
typeLevelError: nil,
|
||||||
functionLevelWarning: 0,
|
functionLevelWarning: 0,
|
||||||
functionLevelError: nil)
|
functionLevelError: nil)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try nestingConfig.apply(configuration: config)
|
try nestingConfig.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
func testSeverityConfigurationThrowsOnBadConfig() {
|
func testSeverityConfigurationThrowsOnBadConfig() {
|
||||||
let config = 17
|
let config = 17
|
||||||
var severityConfig = SeverityConfiguration(.warning)
|
var severityConfig = SeverityConfiguration(.warning)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try severityConfig.apply(configuration: config)
|
try severityConfig.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
func testRegexConfigurationThrows() {
|
func testRegexConfigurationThrows() {
|
||||||
let config = 17
|
let config = 17
|
||||||
var regexConfig = RegexConfiguration(identifier: "")
|
var regexConfig = RegexConfiguration(identifier: "")
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try regexConfig.apply(configuration: config)
|
try regexConfig.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
let config = "unknown"
|
let config = "unknown"
|
||||||
var configuration = TrailingWhitespaceConfiguration(ignoresEmptyLines: false,
|
var configuration = TrailingWhitespaceConfiguration(ignoresEmptyLines: false,
|
||||||
ignoresComments: true)
|
ignoresComments: true)
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: config)
|
try configuration.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
var configuration = ModifierOrderConfiguration()
|
var configuration = ModifierOrderConfiguration()
|
||||||
let config = ["severity": "warning", "preferred_modifier_order": ["specialize"]] as [String: Any]
|
let config = ["severity": "warning", "preferred_modifier_order": ["specialize"]] as [String: Any]
|
||||||
|
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: config)
|
try configuration.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ class RuleConfigurationTests: SwiftLintTestCase {
|
||||||
func testModifierOrderConfigurationThrowsOnNonModifiableGroup() {
|
func testModifierOrderConfigurationThrowsOnNonModifiableGroup() {
|
||||||
var configuration = ModifierOrderConfiguration()
|
var configuration = ModifierOrderConfiguration()
|
||||||
let config = ["severity": "warning", "preferred_modifier_order": ["atPrefixed"]] as [String: Any]
|
let config = ["severity": "warning", "preferred_modifier_order": ["atPrefixed"]] as [String: Any]
|
||||||
checkError(ConfigurationError.unknownConfiguration) {
|
checkError(Issue.unknownConfiguration) {
|
||||||
try configuration.apply(configuration: config)
|
try configuration.apply(configuration: config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class YamlParserTests: SwiftLintTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testParseInvalidStringThrows() {
|
func testParseInvalidStringThrows() {
|
||||||
checkError(YamlParserError.yamlParsing("2:1: error: parser: did not find expected <document start>:\na\n^")) {
|
checkError(Issue.yamlParsing("2:1: error: parser: did not find expected <document start>:\na\n^")) {
|
||||||
_ = try YamlParser.parse("|\na", env: [:])
|
_ = try YamlParser.parse("|\na", env: [:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue