That day when regex can be faster than code

This commit is contained in:
Paul Taykalo
2019-11-12 03:17:41 +02:00
parent d181cb0fd2
commit e00a8bf11a
2 changed files with 6 additions and 5 deletions
+4 -2
View File
@@ -10,10 +10,12 @@
#### Enhancements
* None.
#### Bug Fixes
* Fix false positive for LetVarWhitespaceRule.
[PaulTaykalo](https://github.com/PaulTaykalo)
[#2956](https://github.com/realm/SwiftLint/issues/2956)
* Fix for false-positive identical operands rule.
[PaulTaykalo](https://github.com/PaulTaykalo)
[#2953](https://github.com/realm/SwiftLint/issues/2953)
@@ -196,10 +196,9 @@ public struct LetVarWhitespaceRule: ConfigurationProviderRule, OptInRule, Automa
}
}
let directives: Set = ["#if", "#elseif", "#else", "#endif", "#!", "#warning", "#error"]
let directiveLines = file.lines.filter {
let trimmed = $0.content.trimmingCharacters(in: .whitespaces)
return directives.contains(where: trimmed.hasPrefix)
return regex(#"^\s*#(if|elseif|else|endif|\!|warning|error)"#)
.firstMatch(in: $0.content, options: [], range: $0.content.fullNSRange) != nil
}
result.formUnion(directiveLines.map { $0.index - 1 })