Skip to content

Commit

Permalink
Add max number if params allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kimdv committed Sep 2, 2024
1 parent 94d4f7a commit 48c7fb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ struct MultilineParametersConfiguration: SeverityBasedRuleConfiguration {
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "allows_single_line")
private(set) var allowsSingleLine = true
@ConfigurationElement(key: "max_number_of_params")
private(set) var maxNumberOfParams: Int?
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ private extension MultilineParametersRule {
return false
}

if let maxNumberOfParams = configuration.maxNumberOfParams,
signature.parameterClause.parameters.count <= maxNumberOfParams {
return false
}

var numberOfParameters = 0
var linesWithParameters = Set<Int>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ internal struct MultilineParametersRuleExamples {
) { }
}
""", configuration: ["allows_single_line": false]),
Example("func foo(param1: Int, param2: Bool, param3: [String]) { }",
configuration: ["max_number_of_params": 3]),
]

static let triggeringExamples: [Example] = [
Expand Down Expand Up @@ -336,5 +338,10 @@ 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_params": 2]),
]
}

0 comments on commit 48c7fb4

Please sign in to comment.