Skip to content

Commit

Permalink
Move Configuration.defaultIndentation() to IndentationStyle init
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Jan 4, 2018
1 parent fa13551 commit 34d2fb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Expand Up @@ -13,6 +13,14 @@ public extension Configuration {

public static var `default` = spaces(count: 4)

internal init?(_ object: Any?) {
switch object {
case let value as Int: self = .spaces(count: value)
case let value as String where value == "tabs": self = .tabs
default: return nil
}
}

// MARK: Equatable

public static func == (lhs: IndentationStyle, rhs: IndentationStyle) -> Bool {
Expand Down
15 changes: 4 additions & 11 deletions Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
Expand Up @@ -41,16 +41,6 @@ extension Configuration {
].map({ $0.rawValue }) + ruleList.allValidIdentifiers()
}

private static func defaultIndentation(_ object: Any?) -> IndentationStyle {
switch object {
case let value as Int: return .spaces(count: value)
case let value as String where value == "tabs": return .tabs
default:
queuedPrintError("Invalid configuration for '\(Key.indentation)'. Falling back to default.")
return .default
}
}

public init?(dict: [String: Any], ruleList: RuleList = masterRuleList, enableAllRules: Bool = false,
cachePath: String? = nil) {
func defaultStringArray(_ object: Any?) -> [String] {
Expand All @@ -72,7 +62,10 @@ extension Configuration {
let whitelistRules = defaultStringArray(dict[Key.whitelistRules.rawValue])
let included = defaultStringArray(dict[Key.included.rawValue])
let excluded = defaultStringArray(dict[Key.excluded.rawValue])
let indentation = Configuration.defaultIndentation(dict[Key.indentation.rawValue])
let indentation = Configuration.IndentationStyle(dict[Key.indentation.rawValue]) ?? {
queuedPrintError("Invalid configuration for '\(Key.indentation)'. Falling back to default.")
return .default
}()

Configuration.warnAboutDeprecations(configurationDictionary: dict, disabledRules: disabledRules,
optInRules: optInRules, whitelistRules: whitelistRules, ruleList: ruleList)
Expand Down

0 comments on commit 34d2fb3

Please sign in to comment.