From fcd30c5b7231a5c84d425d830c8f70b790919fd6 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Wed, 8 Jun 2016 15:10:10 +0900 Subject: [PATCH] Skip checking existence of trailing comment in `CommaRule` if already violating Fix #683 --- CHANGELOG.md | 4 ++++ Source/SwiftLintFramework/Rules/CommaRule.swift | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7585f76a64..bc6ef6c2af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,10 @@ [Andrew Rahn](https://github.com/paddlefish) [#667](https://github.com/realm/SwiftLint/issues/667) +* Fix `CommaRule` ignored some violations when trailing comment exists. + [Norio Nomura](https://github.com/norio-nomura) + [#683](https://github.com/realm/SwiftLint/issues/683) + ## 0.10.0: `laundry-select` edition ##### Breaking diff --git a/Source/SwiftLintFramework/Rules/CommaRule.swift b/Source/SwiftLintFramework/Rules/CommaRule.swift index ac92b9b2e1..1912a32879 100644 --- a/Source/SwiftLintFramework/Rules/CommaRule.swift +++ b/Source/SwiftLintFramework/Rules/CommaRule.swift @@ -112,6 +112,12 @@ public struct CommaRule: CorrectableRule, ConfigurationProviderRule { return nil } + // If the first range does not start with comma, it already violates this rule + // whatever is contained in the second range. + if !(contents as NSString).substringWithRange(firstRange).hasPrefix(",") { + return firstRange + } + // check second captured range let secondRange = match.rangeAtIndex(2) guard let matchByteSecondRange = contents