Skip to content

Commit

Permalink
Optimize correction and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
colejd committed Jul 24, 2018
1 parent aec0e98 commit 9712d8e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions Source/SwiftLintFramework/Rules/ControlStatementRule.swift
Expand Up @@ -211,22 +211,21 @@ public struct ControlStatementRule: ConfigurationProviderRule, AutomaticTestable

return statementPatterns.flatMap { pattern -> [NSRange] in
return file.match(pattern: pattern)
// Filter out false positives
.filter { match, syntaxKinds -> Bool in
.compactMap { match, syntaxKinds -> NSRange? in
// Filter out false positives
let matchString = file.contents.substring(from: match.location, length: match.length)
return !isFalsePositive(matchString, syntaxKind: syntaxKinds.first)
}
// Filter out call expressions
.filter { match, _ -> Bool in
if isFalsePositive(matchString, syntaxKind: syntaxKinds.first) {
return nil
}

let contents = file.contents.bridge()
guard let byteOffset = contents.NSRangeToByteRange(start: match.location, length: 1)?.location,
let outerKind = file.structure.kinds(forByteOffset: byteOffset).last else {
return true
return match
}
return SwiftExpressionKind(rawValue: outerKind.kind) != .call
}
.map { match, _ in
return match

// Filter out call expressions
return (SwiftExpressionKind(rawValue: outerKind.kind) != .call) ? match : nil
}
}

Expand Down

0 comments on commit 9712d8e

Please sign in to comment.