mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
40828dff03
* master: (41 commits) Fix formatting in CHANGELOG.md release 0.13.0 Update CHANGELOG.md Fix check for trailing whitespace to return early Fix checks for some inline comments Replace check for comments to use SyntaxKind Add configuration for trailing_whitespace to ignore comments Unwanted space removed - Lint issues fixed Updated HTML Reporter PR feedback Add check on autocorrect for disabled range Use `utf8.count` instead of `utf16.count` to byte range Re-write `ExplicitInitRule` to `ASTRule` added ExplicitInitRule Updated CHANGELOG HTML Reporter added HTML Reporter added Adds information about SwiftLint plugin for AppCode into README.md added reasons why a new rule should be opt in ... # Conflicts: # Source/SwiftLintFramework/Extensions/File+SwiftLint.swift # Source/SwiftLintFramework/Extensions/Structure+SwiftLint.swift # Source/SwiftLintFramework/Rules/ColonRule.swift # Source/SwiftLintFramework/Rules/CommaRule.swift # Source/SwiftLintFramework/Rules/LegacyCGGeometryFunctionsRule.swift # Source/SwiftLintFramework/Rules/LegacyConstantRule.swift # Source/SwiftLintFramework/Rules/LegacyConstructorRule.swift # Source/SwiftLintFramework/Rules/LegacyNSGeometryFunctionsRule.swift # Source/SwiftLintFramework/Rules/LineLengthRule.swift # Source/SwiftLintFramework/Rules/OperatorFunctionWhitespaceRule.swift # Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift # Source/SwiftLintFramework/Rules/RuleConfigurations/StatementPositionConfiguration.swift # Source/SwiftLintFramework/Rules/StatementPositionRule.swift # Source/SwiftLintFramework/Rules/TrailingWhitespaceRule.swift # Tests/SwiftLintFramework/RuleConfigurationTests.swift
56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
//
|
|
// StatementPositionConfiguration.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by Michael Skiba on 6/8/16.
|
|
// Copyright © 2016 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public enum StatementModeConfiguration: String {
|
|
case Default = "default", UncuddledElse = "uncuddled_else"
|
|
|
|
init(value: Any) throws {
|
|
if let string = (value as? String)?.lowercased(),
|
|
let value = StatementModeConfiguration(rawValue: string) {
|
|
self = value
|
|
} else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public struct StatementConfiguration: RuleConfiguration, Equatable {
|
|
public var consoleDescription: String {
|
|
return "(statement_mode) \(statementMode.rawValue), " +
|
|
"(severity) \(severity.consoleDescription)"
|
|
}
|
|
|
|
var statementMode: StatementModeConfiguration
|
|
var severity: SeverityConfiguration
|
|
|
|
public init(statementMode: StatementModeConfiguration,
|
|
severity: SeverityConfiguration) {
|
|
self.statementMode = statementMode
|
|
self.severity = severity
|
|
}
|
|
|
|
public mutating func applyConfiguration(_ configuration: Any) throws {
|
|
guard let configurationDict = configuration as? [String: Any] else {
|
|
throw ConfigurationError.unknownConfiguration
|
|
}
|
|
if let statementModeConfiguration = configurationDict["statement_mode"] {
|
|
try statementMode = StatementModeConfiguration(value: statementModeConfiguration)
|
|
}
|
|
if let severityConfiguration = configurationDict["severity"] {
|
|
try severity.applyConfiguration(severityConfiguration)
|
|
}
|
|
}
|
|
}
|
|
|
|
public func == (lhs: StatementConfiguration, rhs: StatementConfiguration) -> Bool {
|
|
return lhs.statementMode == rhs.statementMode && lhs.severity == rhs.severity
|
|
}
|