From 9d31eaccda4e2e27009231c040f88ee555da0e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Sun, 23 Apr 2017 10:40:37 +0100 Subject: [PATCH] Rename option to validates_start_lowercase --- .../Rules/IdentifierNameRule.swift | 2 +- .../RuleConfigurations/NameConfiguration.swift | 17 ++++++++++------- .../IdentifierNameRuleTests.swift | 2 +- .../RuleConfigurationTests.swift | 8 ++++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/IdentifierNameRule.swift b/Source/SwiftLintFramework/Rules/IdentifierNameRule.swift index 3d2bfd088..63b935a35 100644 --- a/Source/SwiftLintFramework/Rules/IdentifierNameRule.swift +++ b/Source/SwiftLintFramework/Rules/IdentifierNameRule.swift @@ -72,7 +72,7 @@ public struct IdentifierNameRule: ASTRule, ConfigurationProviderRule { } } - let requiresCaseCheck = !configuration.ignoresStartWithLowercase || isFunction + let requiresCaseCheck = configuration.validatesStartWithLowercase || isFunction if requiresCaseCheck && kind != .varStatic && name.isViolatingCase && !name.isOperator { let reason = "\(type) name should start with a lowercase character: '\(name)'" diff --git a/Source/SwiftLintFramework/Rules/RuleConfigurations/NameConfiguration.swift b/Source/SwiftLintFramework/Rules/RuleConfigurations/NameConfiguration.swift index 4f1fd7f0e..98b573c56 100644 --- a/Source/SwiftLintFramework/Rules/RuleConfigurations/NameConfiguration.swift +++ b/Source/SwiftLintFramework/Rules/RuleConfigurations/NameConfiguration.swift @@ -11,14 +11,17 @@ import Foundation public struct NameConfiguration: RuleConfiguration, Equatable { public var consoleDescription: String { return "(min_length) \(minLength.shortConsoleDescription), " + - "(max_length) \(maxLength.shortConsoleDescription)" + "(max_length) \(maxLength.shortConsoleDescription), " + + "excluded: \(excluded), " + + "allowed_symbols: \(allowedSymbols), " + + "validates_start_with_lowercase: \(validatesStartWithLowercase)" } var minLength: SeverityLevelsConfiguration var maxLength: SeverityLevelsConfiguration var excluded: Set var allowedSymbols: Set - var ignoresStartWithLowercase: Bool + var validatesStartWithLowercase: Bool var minLengthThreshold: Int { return max(minLength.warning, minLength.error ?? minLength.warning) @@ -34,12 +37,12 @@ public struct NameConfiguration: RuleConfiguration, Equatable { maxLengthError: Int, excluded: [String] = [], allowedSymbols: [String] = [], - ignoresStartWithLowercase: Bool = false) { + validatesStartWithLowercase: Bool = true) { minLength = SeverityLevelsConfiguration(warning: minLengthWarning, error: minLengthError) maxLength = SeverityLevelsConfiguration(warning: maxLengthWarning, error: maxLengthError) self.excluded = Set(excluded) self.allowedSymbols = Set(allowedSymbols) - self.ignoresStartWithLowercase = ignoresStartWithLowercase + self.validatesStartWithLowercase = validatesStartWithLowercase } public mutating func apply(configuration: Any) throws { @@ -59,8 +62,8 @@ public struct NameConfiguration: RuleConfiguration, Equatable { if let allowedSymbols = [String].array(of: configurationDict["allowed_symbols"]) { self.allowedSymbols = Set(allowedSymbols) } - if let ignoresStartWithLowercase = configurationDict["ignores_start_lowercase"] as? Bool { - self.ignoresStartWithLowercase = ignoresStartWithLowercase + if let validatesStartWithLowercase = configurationDict["validates_start_lowercase"] as? Bool { + self.validatesStartWithLowercase = validatesStartWithLowercase } } } @@ -70,7 +73,7 @@ public func == (lhs: NameConfiguration, rhs: NameConfiguration) -> Bool { lhs.maxLength == rhs.maxLength && zip(lhs.excluded, rhs.excluded).reduce(true) { $0 && ($1.0 == $1.1) } && zip(lhs.allowedSymbols, rhs.allowedSymbols).reduce(true) { $0 && ($1.0 == $1.1) } && - lhs.ignoresStartWithLowercase == rhs.ignoresStartWithLowercase + lhs.validatesStartWithLowercase == rhs.validatesStartWithLowercase } // MARK: - ConfigurationProviderRule extensions diff --git a/Tests/SwiftLintFrameworkTests/IdentifierNameRuleTests.swift b/Tests/SwiftLintFrameworkTests/IdentifierNameRuleTests.swift index 2cc2cbeb4..b426c1f20 100644 --- a/Tests/SwiftLintFrameworkTests/IdentifierNameRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/IdentifierNameRuleTests.swift @@ -51,7 +51,7 @@ class IdentifierNameRuleTests: XCTestCase { corrections: baseDescription.corrections, deprecatedAliases: baseDescription.deprecatedAliases) - verifyRule(description, ruleConfiguration: ["ignores_start_lowercase": true]) + verifyRule(description, ruleConfiguration: ["validates_start_lowercase": false]) } } diff --git a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift index da0c6a5b7..207030a7e 100644 --- a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift @@ -16,7 +16,9 @@ class RuleConfigurationsTests: XCTestCase { func testNameConfigurationSetsCorrectly() { let config = [ "min_length": ["warning": 17, "error": 7], "max_length": ["warning": 170, "error": 700], - "excluded": "id"] as [String: Any] + "excluded": "id", + "allowed_symbols": ["$"], + "validates_start_lowercase": false] as [String: Any] var nameConfig = NameConfiguration(minLengthWarning: 0, minLengthError: 0, maxLengthWarning: 0, @@ -25,7 +27,9 @@ class RuleConfigurationsTests: XCTestCase { minLengthError: 7, maxLengthWarning: 170, maxLengthError: 700, - excluded: ["id"]) + excluded: ["id"], + allowedSymbols: ["$"], + validatesStartWithLowercase: false) do { try nameConfig.apply(configuration: config) XCTAssertEqual(nameConfig, comp)