From a4d32cfa67bd7c899c0de3c819f58ee2fa3bb93d Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Tue, 5 Apr 2016 09:56:43 -0400 Subject: [PATCH] Don't trigger ClosingBraceRule across line breaks Closes #592 --- CHANGELOG.md | 4 ++++ Source/SwiftLintFramework/Rules/ClosingBraceRule.swift | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c987be3aa..d534c60ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ [Norio Nomura](https://github.com/norio-nomura) [#593](https://github.com/realm/SwiftLint/issues/593) +* `ClosingBraceRule` no longer triggers across line breaks. + [Josh Friend](https://github.com/joshfriend) + [#592](https://github.com/realm/SwiftLint/issues/592) + ## 0.9.2: Multiple Exhaust Codes ##### Breaking diff --git a/Source/SwiftLintFramework/Rules/ClosingBraceRule.swift b/Source/SwiftLintFramework/Rules/ClosingBraceRule.swift index f90ecf451..ad9a860b4 100644 --- a/Source/SwiftLintFramework/Rules/ClosingBraceRule.swift +++ b/Source/SwiftLintFramework/Rules/ClosingBraceRule.swift @@ -14,7 +14,7 @@ private let whitespaceAndNewlineCharacterSet = NSCharacterSet.whitespaceAndNewli extension File { private func violatingClosingBraceRanges() -> [NSRange] { return matchPattern( - "(\\}\\s+\\))", + "(\\}[ \\t]+\\))", excludingSyntaxKinds: SyntaxKind.commentAndStringKinds() ) } @@ -32,16 +32,19 @@ public struct ClosingBraceRule: CorrectableRule, ConfigurationProviderRule { description: "Closing brace with closing parenthesis " + "should not have any whitespaces in the middle.", nonTriggeringExamples: [ - "[].map({ })" + "[].map({ })", + "[].map(\n { }\n)" ], triggeringExamples: [ - "[].map({ ↓} )" + "[].map({ ↓} )", + "[].map({ }\t)" ], corrections: [ "[].map({ } )\n": "[].map({ })\n" ] ) + public func validateFile(file: File) -> [StyleViolation] { return file.violatingClosingBraceRanges().map { StyleViolation(ruleDescription: self.dynamicType.description,