diff --git a/Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/MultilineParametersConfiguration.swift b/Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/MultilineParametersConfiguration.swift index f8705d7cb0..87b38b39ee 100644 --- a/Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/MultilineParametersConfiguration.swift +++ b/Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/MultilineParametersConfiguration.swift @@ -8,4 +8,6 @@ struct MultilineParametersConfiguration: SeverityBasedRuleConfiguration { private(set) var severityConfiguration = SeverityConfiguration(.warning) @ConfigurationElement(key: "allows_single_line") private(set) var allowsSingleLine = true + @ConfigurationElement(key: "max_number_of_single_line_parameters") + private(set) var maxNumberOfSingleLineParameters: Int? } diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRule.swift index 281e97a504..6e66243f93 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRule.swift @@ -43,6 +43,12 @@ private extension MultilineParametersRule { numberOfParameters += 1 } + if let maxNumberOfParams = configuration.maxNumberOfParams, + configuration.allowsSingleLine, + numberOfParameters > maxNumberOfParams { + return true + } + guard linesWithParameters.count > (configuration.allowsSingleLine ? 1 : 0), numberOfParameters != linesWithParameters.count else { return false diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRuleExamples.swift b/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRuleExamples.swift index e87e35359b..35446334ed 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRuleExamples.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRuleExamples.swift @@ -197,6 +197,13 @@ internal struct MultilineParametersRuleExamples { ) { } } """, configuration: ["allows_single_line": false]), + Example("func foo(param1: Int, param2: Bool, param3: [String]) { }", + configuration: ["max_number_of_single_line_parameters": 3]), + Example(""" + func foo(param1: Int, + param2: Bool, + param3: [String]) { } + """, configuration: ["max_number_of_single_line_parameters": 3]), ] static let triggeringExamples: [Example] = [ @@ -336,5 +343,19 @@ internal struct MultilineParametersRuleExamples { configuration: ["allows_single_line": false]), Example("func ↓foo(param1: Int, param2: Bool, param3: [String]) { }", configuration: ["allows_single_line": false]), + Example("func ↓foo(param1: Int, param2: Bool, param3: [String]) { }", + configuration: ["max_number_of_single_line_parameters": 2]), + Example(""" + func ↓foo(param1: Int, + param2: Bool, param3: [String]) { } + """, + configuration: ["max_number_of_single_line_parameters": 3]), + Example(""" + func ↓foo(param1: Int, param2: Bool) { } + """, + configuration: [ + "max_number_of_single_line_parameters": 3, + "allows_single_line": false, + ]), ] }