<commit_before>//
//  SeverityConfig.swift
//  SwiftLint
//
//  Created by <NAME> on 1/20/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation

public struct SeverityConfig: RuleConfig, Equatable {
    var severity: ViolationSeverity

    public init(_ severity: ViolationSeverity) {
        self.severity = severity
    }

    public mutating func setConfig(config: AnyObject) throws {
        let value = config as? String ?? (config as? [String: AnyObject])?["severity"] as? String
        if let value = value, let severity = ViolationSeverity(rawValue: value.capitalizedString) {
            self.severity = severity
        } else {
            throw ConfigurationError.UnknownConfiguration
        }
    }

    public func isEqualTo(ruleConfig: RuleConfig) -> Bool {
        if let config = ruleConfig as? SeverityConfig {
            return self == config
        }
        return false
    }
}

public func == (lhs: SeverityConfig, rhs: SeverityConfig) -> Bool {
    return lhs.severity == rhs.severity
}<commit_msg>Extracted ViolationSeverity initialization via unnormalized String to extension.<commit_after>//
//  SeverityConfig.swift
//  SwiftLint
//
//  Created by <NAME> on 1/20/16.
//  Copyright © 2016 Realm. All rights reserved.
//

import Foundation

public struct SeverityConfig: RuleConfig, Equatable {
    var severity: ViolationSeverity

    public init(_ severity: ViolationSeverity) {
        self.severity = severity
    }

    public mutating func setConfig(config: AnyObject) throws {
        let value = config as? String ?? (config as? [String: AnyObject])?["severity"] as? String
        if let value = value, let severity = ViolationSeverity(unnormalized: value) {
            self.severity = severity
        } else {
            throw ConfigurationError.UnknownConfiguration
        }
    }

    public func isEqualTo(ruleConfig: RuleConfig) -> Bool {
        if let config = ruleConfig as? SeverityConfig {
            return self == config
        }
        return false
    }
}

public func == (lhs: SeverityConfig, rhs: SeverityConfig) -> Bool {
    return lhs.severity == rhs.severity
}

// MARK: - ViolationSeverity extensions

public extension ViolationSeverity {
    init?(unnormalized: String) {
        self.init(rawValue: unnormalized.lowercaseString.capitalizedString)
    }
}
{'fraction_non_alphanumeric': 0.09385665529010238, 'fraction_numerical': 0.007679180887372013, 'mean_word_length': 2.734076433121019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275713', 'n_tokens_mistral': 704, 'n_tokens_neox': 656, 'n_words': 191}