From 714902ef0197861614319f3509573370cd54ea09 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Sat, 6 Feb 2016 14:56:59 -0800 Subject: [PATCH] treat single values as an array in the configuration dictionary --- CHANGELOG.md | 6 ++++++ .../Models/Configuration.swift | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215d94c8a..15fbbbb14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,12 @@ [JP Simard](https://github.com/jpsim) [#386](https://github.com/realm/SwiftLint/issues/386) +* All top-level keys in a configuration file that accept an array now also + accept a single value. + e.g. `included: Source` is equivalent to `included:\n - Source`. + [JP Simard](https://github.com/jpsim) + [#120](https://github.com/realm/SwiftLint/issues/120) + ##### Bug Fixes * Fix case sensitivity of keywords for `valid_docs`. diff --git a/Source/SwiftLintFramework/Models/Configuration.swift b/Source/SwiftLintFramework/Models/Configuration.swift index c6839a25f..e502aac5b 100644 --- a/Source/SwiftLintFramework/Models/Configuration.swift +++ b/Source/SwiftLintFramework/Models/Configuration.swift @@ -104,9 +104,15 @@ public struct Configuration: Equatable { "future release.") } + func defaultStringArray(object: AnyObject?) -> [String] { + return [String].arrayOf(object) ?? [] + } + // Use either new 'opt_in_rules' or deprecated 'enabled_rules' for now. - let optInRules = dict[ConfigurationKey.OptInRules.rawValue] as? [String] ?? - dict[ConfigurationKey.EnabledRules.rawValue] as? [String] ?? [] + let optInRules = defaultStringArray( + dict[ConfigurationKey.OptInRules.rawValue] ?? + dict[ConfigurationKey.EnabledRules.rawValue] + ) // Log an error when supplying invalid keys in the configuration dictionary let validKeys = [ @@ -126,11 +132,11 @@ public struct Configuration: Equatable { } self.init( - disabledRules: dict[ConfigurationKey.DisabledRules.rawValue] as? [String] ?? [], + disabledRules: defaultStringArray(dict[ConfigurationKey.DisabledRules.rawValue]), optInRules: optInRules, - whitelistRules: dict[ConfigurationKey.WhitelistRules.rawValue] as? [String] ?? [], - included: dict[ConfigurationKey.Included.rawValue] as? [String] ?? [], - excluded: dict[ConfigurationKey.Excluded.rawValue] as? [String] ?? [], + whitelistRules: defaultStringArray(dict[ConfigurationKey.WhitelistRules.rawValue]), + included: defaultStringArray(dict[ConfigurationKey.Included.rawValue]), + excluded: defaultStringArray(dict[ConfigurationKey.Excluded.rawValue]), reporter: dict[ConfigurationKey.Reporter.rawValue] as? String ?? XcodeReporter.identifier, useNestedConfigs: dict[ConfigurationKey.UseNestedConfigs.rawValue] as? Bool ?? false,