Skip to content

Commit

Permalink
optimize ForceUnwrappingRule
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Jan 26, 2016
1 parent 0183235 commit 614c27a
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions Source/SwiftLintFramework/Rules/ForceUnwrappingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,10 @@ public struct ForceUnwrappingRule: OptInRule, ConfigProviderRule {
)

public func validateFile(file: File) -> [StyleViolation] {
// Get all identifiers from syntax map
let identifiers = file.syntaxMap.tokens.filter({
$0.type == SyntaxKind.Identifier.rawValue
}).flatMap({
file.contents.substringWithByteRange(start: $0.offset, length: $0.length)
})
// Check if there is any identifier followed by a '!'
let violations = Set(identifiers).flatMap({
return file.matchPattern("\($0)(\\((?:[^\\r\\n]|\\r(?!\\n))*?\\))?\\!")
}).filter({ $0.1.first == .Identifier }).map({ $0.0 })

return violations.map {
return file.matchPattern("[\\w)]+!", withSyntaxKinds: [.Identifier]).map {
StyleViolation(ruleDescription: self.dynamicType.description,
severity: config.severity,
location: Location(file: file, characterOffset: $0.location + $0.length - 1))
location: Location(file: file, characterOffset: NSMaxRange($0) - 1))
}
}
}

0 comments on commit 614c27a

Please sign in to comment.