Files
SwiftLint/Source/SwiftLintFramework/Models/Region.swift
T
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00

45 lines
1.5 KiB
Swift

import Foundation
import SourceKittenFramework
public struct Region: Equatable {
public let start: Location
public let end: Location
public let disabledRuleIdentifiers: Set<RuleIdentifier>
public init(start: Location, end: Location, disabledRuleIdentifiers: Set<RuleIdentifier>) {
self.start = start
self.end = end
self.disabledRuleIdentifiers = disabledRuleIdentifiers
}
public func contains(_ location: Location) -> Bool {
return start <= location && end >= location
}
public func isRuleEnabled(_ rule: Rule) -> Bool {
return !isRuleDisabled(rule)
}
public func isRuleDisabled(_ rule: Rule) -> Bool {
guard !disabledRuleIdentifiers.contains(.all) else {
return true
}
let identifiersToCheck = type(of: rule).description.allIdentifiers
let regionIdentifiers = Set(disabledRuleIdentifiers.map { $0.stringRepresentation })
return !regionIdentifiers.isDisjoint(with: identifiersToCheck)
}
public func deprecatedAliasesDisabling(rule: Rule) -> Set<String> {
let identifiers = type(of: rule).description.deprecatedAliases
return Set(disabledRuleIdentifiers.map { $0.stringRepresentation }).intersection(identifiers)
}
}
// MARK: Equatable
public func == (lhs: Region, rhs: Region) -> Bool {
return lhs.start == rhs.start &&
lhs.end == rhs.end &&
lhs.disabledRuleIdentifiers == rhs.disabledRuleIdentifiers
}