mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
d387532929
For a function that takes a closure as default value, the array of
parameter reported by sourcekit also includes the parameters of that
closure.
In other words, a function like
func foo(param1: Int,
param2: Bool,
param3: (Int) -> Void = { (x: Int) in }) { }
reports 4 parameters (param 1, param2, param3, and x).
This commit uses the bounds of the method/function parameters to filter
out parameters within parameters. Below, a 1, a 2, and a 3 would be
filtered out since they're inside parameter 3.
----------------------------------------------------------------|
| |---------| |---------| |----------------------------| |
| | param 1 | | param 2 | | param 3: |a 1| |a 2| |a 3| | |
| |---------| |---------| |----------------------------| |
----------------------------------------------------------------|
227 lines
9.1 KiB
Swift
227 lines
9.1 KiB
Swift
//
|
|
// MultilineParametersRuleExamples.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by Ornithologist Coder on 22/05/17.
|
|
// Copyright © 2017 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// swiftlint:disable type_body_length
|
|
|
|
internal struct MultilineParametersRuleExamples {
|
|
static let nonTriggeringExamples = [
|
|
"func foo() { }",
|
|
"func foo(param1: Int) { }",
|
|
"func foo(param1: Int, param2: Bool) { }",
|
|
"func foo(param1: Int, param2: Bool, param3: [String]) { }",
|
|
"func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }",
|
|
"func foo(_ param1: Int, param2: Int, param3: Int) -> (Int) -> Int {\n" +
|
|
" return { x in x + param1 + param2 + param3 }\n" +
|
|
"}",
|
|
"static func foo() { }",
|
|
"static func foo(param1: Int) { }",
|
|
"static func foo(param1: Int, param2: Bool) { }",
|
|
"static func foo(param1: Int, param2: Bool, param3: [String]) { }",
|
|
"static func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }",
|
|
"protocol Foo {\n\tfunc foo() { }\n}",
|
|
"protocol Foo {\n\tfunc foo(param1: Int) { }\n}",
|
|
"protocol Foo {\n\tfunc foo(param1: Int, param2: Bool) { }\n}",
|
|
"protocol Foo {\n\tfunc foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"protocol Foo {\n" +
|
|
" func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n\tstatic func foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"protocol Foo {\n" +
|
|
" static func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n\tclass func foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"protocol Foo {\n" +
|
|
" class func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n\tfunc foo() { }\n}",
|
|
"enum Foo {\n\tfunc foo(param1: Int) { }\n}",
|
|
"enum Foo {\n\tfunc foo(param1: Int, param2: Bool) { }\n}",
|
|
"enum Foo {\n\tfunc foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"enum Foo {\n" +
|
|
" func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n\tstatic func foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"enum Foo {\n" +
|
|
" static func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n\tfunc foo() { }\n}",
|
|
"struct Foo {\n\tfunc foo(param1: Int) { }\n}",
|
|
"struct Foo {\n\tfunc foo(param1: Int, param2: Bool) { }\n}",
|
|
"struct Foo {\n\tfunc foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"struct Foo {\n" +
|
|
" func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n\tstatic func foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"struct Foo {\n" +
|
|
" static func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n\tfunc foo() { }\n}",
|
|
"class Foo {\n\tfunc foo(param1: Int) { }\n}",
|
|
"class Foo {\n\tfunc foo(param1: Int, param2: Bool) { }\n}",
|
|
"class Foo {\n\tfunc foo(param1: Int, param2: Bool, param3: [String]) { }\n\t}",
|
|
"class Foo {\n" +
|
|
" func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n\tclass func foo(param1: Int, param2: Bool, param3: [String]) { }\n}",
|
|
"class Foo {\n" +
|
|
" 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" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func foo(param1: Int,\n" +
|
|
" param2: @escaping ((Int) -> Void)? = { _ in },\n" +
|
|
" param3: Bool) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func foo(param1: Int,\n" +
|
|
" param2: @escaping ((Int) -> Void)? = { _ in },\n" +
|
|
" param3: @escaping (Int, Int) -> Void = { _, _ in }) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: @escaping (Int) -> Void = { (x: Int) in }) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func foo(param1: Int,\n" +
|
|
" param2: Bool,\n" +
|
|
" param3: @escaping (Int, (Int) -> Void) -> Void = { (x: Int, f: (Int) -> Void) in }) { }\n" +
|
|
"}"
|
|
]
|
|
|
|
static let triggeringExamples = [
|
|
"func ↓foo(_ param1: Int,\n" +
|
|
" param2: Int, param3: Int) -> (Int) -> Int {\n" +
|
|
" return { x in x + param1 + param2 + param3 }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" static func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" static func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" class func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"protocol Foo {\n" +
|
|
" class func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n" +
|
|
" func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n" +
|
|
" func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n" +
|
|
" static func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"enum Foo {\n" +
|
|
" static func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n" +
|
|
" func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n" +
|
|
" func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n" +
|
|
" static func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"struct Foo {\n" +
|
|
" static func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func ↓foo(param1: Int, param2: Bool,\n" +
|
|
" param3: [String]) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: @escaping (Int, Int) -> Void = { _, _ in }) { }\n" +
|
|
"}",
|
|
"class Foo {\n" +
|
|
" class func ↓foo(param1: Int,\n" +
|
|
" param2: Bool, param3: @escaping (Int) -> Void = { (x: Int) in }) { }\n" +
|
|
"}"
|
|
]
|
|
}
|