Skip to content

Commit

Permalink
Merge pull request realm#1582 from nevil/ah-void-wrapped-in-paren
Browse files Browse the repository at this point in the history
Match `(Void)` as return type in the `void_return` rule
  • Loading branch information
marcelofabri authored May 29, 2017
2 parents da7c0d9 + 7126d9a commit 2628c9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

##### Enhancements

* Match `(Void)` as return type in the `void_return` rule.
[Anders Hasselqvist](https://github.com/nevil)

* Add `multiline_parameters` opt-in rule that warns to either keep
all the parameters of a method or function on the same line,
or one per line.
Expand Down
9 changes: 8 additions & 1 deletion Source/SwiftLintFramework/Rules/VoidReturnRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct VoidReturnRule: ConfigurationProviderRule, CorrectableRule {
description: "Prefer `-> Void` over `-> ()`.",
nonTriggeringExamples: [
"let abc: () -> Void = {}\n",
"let abc: () -> (VoidVoid) = {}\n",
"func foo(completion: () -> Void)\n",
"let foo: (ConfigurationTests) -> () throws -> Void)\n",
"let foo: (ConfigurationTests) -> () throws -> Void)\n",
Expand All @@ -28,14 +29,20 @@ public struct VoidReturnRule: ConfigurationProviderRule, CorrectableRule {
],
triggeringExamples: [
"let abc: () -> ↓() = {}\n",
"let abc: () -> ↓(Void) = {}\n",
"let abc: () -> ↓( Void ) = {}\n",
"func foo(completion: () -> ↓())\n",
"func foo(completion: () -> ↓( ))\n",
"func foo(completion: () -> ↓(Void))\n",
"let foo: (ConfigurationTests) -> () throws -> ↓())\n"
],
corrections: [
"let abc: () -> ↓() = {}\n": "let abc: () -> Void = {}\n",
"let abc: () -> ↓(Void) = {}\n": "let abc: () -> Void = {}\n",
"let abc: () -> ↓( Void ) = {}\n": "let abc: () -> Void = {}\n",
"func foo(completion: () -> ↓())\n": "func foo(completion: () -> Void)\n",
"func foo(completion: () -> ↓( ))\n": "func foo(completion: () -> Void)\n",
"func foo(completion: () -> ↓(Void))\n": "func foo(completion: () -> Void)\n",
"let foo: (ConfigurationTests) -> () throws -> ↓())\n":
"let foo: (ConfigurationTests) -> () throws -> Void)\n"
]
Expand All @@ -51,7 +58,7 @@ public struct VoidReturnRule: ConfigurationProviderRule, CorrectableRule {

private func violationRanges(file: File) -> [NSRange] {
let kinds = SyntaxKind.commentAndStringKinds()
let parensPattern = "\\(\\s*\\)"
let parensPattern = "\\(\\s*(?:Void)?\\s*\\)"
let pattern = "->\\s*\(parensPattern)\\s*(?!->)"
let excludingPattern = "(\(pattern))\\s*(throws\\s+)?->"

Expand Down

0 comments on commit 2628c9e

Please sign in to comment.