Files
SwiftLint/Source/SwiftLintFramework/Rules/ForceCastRule.swift
T
JP Simard 989127cbe0 [StyleViolation] use RuleDescription's description when reason is nil
Many cases just used a static string that was nearly identical to the rule
description as the `reason` parameter when initializing a StyleViolation.
2015-11-17 10:25:57 -08:00

31 lines
855 B
Swift

//
// ForceCastRule.swift
// SwiftLint
//
// Created by JP Simard on 2015-05-16.
// Copyright (c) 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public struct ForceCastRule: Rule {
public init() {}
public static let description = RuleDescription(
identifier: "force_cast",
name: "Force Cast",
description: "Force casts should be avoided.",
nonTriggeringExamples: [
"NSNumber() as? Int\n"
],
triggeringExamples: [ "NSNumber() as! Int\n" ]
)
public func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("as!", withSyntaxKinds: [.Keyword]).map {
StyleViolation(ruleDescription: self.dynamicType.description,
severity: .Error, location: Location(file: file, offset: $0.location))
}
}
}