Skip to content

Commit

Permalink
Fix false positive in multiline_parameters rule
Browse files Browse the repository at this point in the history
when parameter is a closure has default value. Fixes #1912.
  • Loading branch information
ornithocoder committed Oct 18, 2017
1 parent 234f987 commit 3ba3fd0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@

##### Bug Fixes

* None.
* Fix false positive in `multiline_parameters` rule when parameter is a closure
with default value.
[Ornithologist Coder](https://github.com/ornithocoder)
[#1912](https://github.com/realm/SwiftLint/issues/1912)

## 0.23.1: Rewash: Forgotten Load Edition

Expand Down
32 changes: 32 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -7014,6 +7014,38 @@ class Foo {
}
```

```swift
class Foo {
class func foo(param1: Int,
param2: Bool,
param3: @escaping (Int, Int) -> Void = { _, _ in }) { }
}
```

```swift
class Foo {
class func foo(param1: Int,
param2: Bool,
param3: @escaping (Int) -> Void = { _ in }) { }
}
```

```swift
class Foo {
class func foo(param1: Int,
param2: Bool,
param3: @escaping ((Int) -> Void)? = nil) { }
}
```

```swift
class Foo {
class func foo(param1: Int,
param2: Bool,
param3: @escaping ((Int) -> Void)? = { _ in }) { }
}
```

</details>
<details>
<summary>Triggering Examples</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public struct MultilineParametersRule: ASTRule, OptInRule, ConfigurationProvider
for structure in dictionary.substructure {
guard
let structureOffset = structure.offset,
structure.typeName != nil,
let structureKind = structure.kind, SwiftDeclarationKind(rawValue: structureKind) == .varParameter,
let (line, _) = file.contents.bridge().lineAndCharacter(forByteOffset: structureOffset),
offset..<(offset + length) ~= structureOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ internal struct MultilineParametersRuleExamples {
" class func foo(param1: Int,\n" +
" param2: Bool,\n" +
" param3: [String]) { }\n" +
"}",
"class Foo {\n" +
" class func foo(param1: Int,\n" +
" param2: Bool,\n" +
" param3: @escaping (Int, Int) -> Void = { _, _ in }) { }\n" +
"}",
"class Foo {\n" +
" class func foo(param1: Int,\n" +
" param2: Bool,\n" +
" param3: @escaping (Int) -> Void = { _ in }) { }\n" +
"}",
"class Foo {\n" +
" class func foo(param1: Int,\n" +
" param2: Bool,\n" +
" param3: @escaping ((Int) -> Void)? = nil) { }\n" +
"}",
"class Foo {\n" +
" class func foo(param1: Int,\n" +
" param2: Bool,\n" +
" param3: @escaping ((Int) -> Void)? = { _ in }) { }\n" +
"}"
]

Expand Down

0 comments on commit 3ba3fd0

Please sign in to comment.