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

Fix trailing_semicolon autocorrect to handle more than one violation per line #472

Merged
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 @@ -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
Expand Down
13 changes: 10 additions & 3 deletions Source/SwiftLintFramework/Rules/TrailingSemicolonRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import SourceKittenFramework

extension File {
private func violatingTrailingSemicolonRanges() -> [NSRange] {
return matchPattern(";$", excludingSyntaxKinds: SyntaxKind.commentAndStringKinds())
return matchPattern("(;+([^\\S\\n]?)*)+;?$",
excludingSyntaxKinds: SyntaxKind.commentAndStringKinds())
}
}

Expand All @@ -28,11 +29,17 @@ 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",
"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",
"let a = 0; ; ;\n": "let a = 0\n"
]
)

Expand Down