Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip braces in regex literals #4091

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ accordingly._
[SimplyDanny](https://github.com/SimplyDanny)
[#4030](https://github.com/realm/SwiftLint/issues/4030)

* Skip braces in regex literals to avoid false positive in `closure_spacing` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#4090](https://github.com/realm/SwiftLint/issues/4090)

#### Bug Fixes

* Fix false positive in `self_in_property_initialization` rule when using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, Op
Example("[].map ({ $0.description })"),
Example("[].filter { $0.contains(location) }"),
Example("extension UITableViewCell: ReusableView { }"),
Example("extension UITableViewCell: ReusableView {}")
Example("extension UITableViewCell: ReusableView {}"),
Example(#"let r = /\{\}/"#, excludeFromDocumentation: true)
],
triggeringExamples: [
Example("[].filter(↓{$0.contains(location)})"),
Expand Down Expand Up @@ -71,7 +72,7 @@ public struct ClosureSpacingRule: CorrectableRule, ConfigurationProviderRule, Op
// returns ranges of braces `{` or `}` in the same line
private func validBraces(in file: SwiftLintFile) -> [NSRange] {
let nsstring = file.contents.bridge()
let bracePattern = regex("\\{|\\}")
let bracePattern = regex(#"(?<!\\)\{|(?<!\\)\}"#)
let linesTokens = file.syntaxTokensByLines
let kindsToExclude = SyntaxKind.commentAndStringKinds

Expand Down