mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
That day when regex can be faster than code
This commit is contained in:
+4
-2
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user