From 4e7325fbd47c1b55d23dac073d024d95ba96fbe9 Mon Sep 17 00:00:00 2001 From: Daniel Beard Date: Tue, 2 Feb 2016 10:29:10 -0800 Subject: [PATCH 1/2] Fix trailing_semicolon autocorrect to handle more than one violation per line --- CHANGELOG.md | 4 ++++ .../Rules/TrailingSemicolonRule.swift | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a6994b854..58fb491141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,10 @@ [diogoguimaraes](https://github.com/diogoguimaraes) [#451](https://github.com/realm/SwiftLint/issues/451) +* Fix `trailing_newline` autocorrect to handle more than one violation per line. + [daniel-beard](https://github.com/daniel-beard) + [#465](https://github.com/realm/SwiftLint/issues/465) + ## 0.7.2: Appliance Manual ##### Breaking diff --git a/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift b/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift index 56a992c92a..51cf481b30 100644 --- a/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift +++ b/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift @@ -11,7 +11,8 @@ import SourceKittenFramework extension File { private func violatingTrailingSemicolonRanges() -> [NSRange] { - return matchPattern(";$", excludingSyntaxKinds: SyntaxKind.commentAndStringKinds()) + return matchPattern(";*([^\\S\\n]?)*;+$", + excludingSyntaxKinds: SyntaxKind.commentAndStringKinds()) } } @@ -28,11 +29,15 @@ public struct TrailingSemicolonRule: CorrectableRule, ConfigProviderRule { nonTriggeringExamples: [ "let a = 0\n" ], triggeringExamples: [ "let a = 0↓;\n", - "let a = 0↓;\nlet b = 1\n" + "let a = 0↓;\nlet b = 1\n", + "let a = 0↓;;\n", + "let a = 0↓; ;;\n" ], corrections: [ "let a = 0;\n": "let a = 0\n", - "let a = 0;\nlet b = 1\n": "let a = 0\nlet b = 1\n" + "let a = 0;\nlet b = 1\n": "let a = 0\nlet b = 1\n", + "let a = 0;;\n": "let a = 0\n", + "let a = 0; ;;\n": "let a = 0\n" ] ) From 5667ab889ce9b67e31770ef3763ac974acc5af24 Mon Sep 17 00:00:00 2001 From: Daniel Beard Date: Tue, 2 Feb 2016 10:37:49 -0800 Subject: [PATCH 2/2] Handle multiple groups --- .../SwiftLintFramework/Rules/TrailingSemicolonRule.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift b/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift index 51cf481b30..d7cdf9288b 100644 --- a/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift +++ b/Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift @@ -11,7 +11,7 @@ import SourceKittenFramework extension File { private func violatingTrailingSemicolonRanges() -> [NSRange] { - return matchPattern(";*([^\\S\\n]?)*;+$", + return matchPattern("(;+([^\\S\\n]?)*)+;?$", excludingSyntaxKinds: SyntaxKind.commentAndStringKinds()) } } @@ -31,13 +31,15 @@ public struct TrailingSemicolonRule: CorrectableRule, ConfigProviderRule { "let a = 0↓;\n", "let a = 0↓;\nlet b = 1\n", "let a = 0↓;;\n", - "let a = 0↓; ;;\n" + "let a = 0↓; ;;\n", + "let a = 0↓; ; ;\n" ], corrections: [ "let a = 0;\n": "let a = 0\n", "let a = 0;\nlet b = 1\n": "let a = 0\nlet b = 1\n", "let a = 0;;\n": "let a = 0\n", - "let a = 0; ;;\n": "let a = 0\n" + "let a = 0; ;;\n": "let a = 0\n", + "let a = 0; ; ;\n": "let a = 0\n" ] )