Skip to content

Commit

Permalink
That day when regex can be faster than code
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulTaykalo committed Nov 12, 2019
1 parent d181cb0 commit e00a8bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit e00a8bf

Please sign in to comment.