import Foundation import SourceKittenFramework public struct ProtocolPropertyAccessorsOrderRule: ConfigurationProviderRule, SubstitutionCorrectableRule, AutomaticTestableRule { public var configuration = SeverityConfiguration(.warning) public init() {} public static let description = RuleDescription( identifier: "protocol_property_accessors_order", name: "Protocol Property Accessors Order", description: "When declaring properties in protocols, the order of accessors should be `get set`.", kind: .style, nonTriggeringExamples: [ Example("protocol Foo {\n var bar: String { get set }\n }"), Example("protocol Foo {\n var bar: String { get }\n }"), Example("protocol Foo {\n var bar: String { set }\n }") ], triggeringExamples: [ Example("protocol Foo {\n var bar: String { ↓set get }\n }") ], corrections: [ Example("protocol Foo {\n var bar: String { ↓set get }\n }"): Example("protocol Foo {\n var bar: String { get set }\n }") ] ) public func validate(file: SwiftLintFile) -> [StyleViolation] { return violationRanges(in: file).map { StyleViolation(ruleDescription: Self.description, severity: configuration.severity, location: Location(file: file, characterOffset: $0.location)) } } public func violationRanges(in file: SwiftLintFile) -> [NSRange] { return file.match(pattern: "\\bset\\s*get\\b", with: [.keyword, .keyword]) } public func substitution(for violationRange: NSRange, in file: SwiftLintFile) -> (NSRange, String)? { return (violationRange, "get set") } }