-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add max number if params allowed for multiline_parameters
#5781
base: main
Are you sure you want to change the base?
Conversation
e7d445b
to
48c7fb4
Compare
Here's an example of your CHANGELOG entry: * Add max number if params allowed for `multiline_parameters`.
[kimdv](https://github.com/kimdv)
[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number) note: There are two invisible spaces after the entry's text. Generated by 🚫 Danger |
@@ -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]) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to make sense of this new option. Why would it be helpful to allow this style given max_number_of_params = 3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Maybe we should only allow x params etc, if they are on the same line?
Would that make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could in this case do the other way around?
So if it's set to 3, and the there is a newline then it will show a warning to put on a single line?
But maybe it would be better in that case to show a warning that all params should be on a newline instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default style the rule enforces is that all parameters are on the same line or every parameter is on a separate line.
Optionally, with allows_single_line = false
, all parameters need to be placed on their own line.
With the new option, you want to allow a specified number of parameters to be placed on a single line. Once the threshold is exceeded, all parameters are required to be placed on a separate line again. That's basically allows_single_line = true
up to a number of parameters.
I think that enforcing a single line is not practicable, because parameters and their types could consume a lot of space and so placing them on separate line, even without the rule enforcing it, should be fine.
Now, how does max_number_of_parameters
(maybe we need a better name) play nicely with allows_single_line = false
? It's a contradiction. On the other hand, allows_single_line = true
is redundant with max_number_of_parameters
being configured with a reasonable number. We somehow need to align both, deprecate or reuse allows_single_line
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so I rearranged some code.
I still think that allows_single_line
and max_number_of_parameters
can live next to each other.
It's just, when allows_single_line
is false
then max_number_of_parameters
is ignored. I think that is fine.
I added a test case, where allow single line is false but there is fewer params than max_number_of_parameters
define.
Also I added one where there is 3 params on each line. Also within the allow number in max_number_of_parameters
.
Source/SwiftLintBuiltInRules/Rules/Style/MultilineParametersRule.swift
Outdated
Show resolved
Hide resolved
00ab0c9
to
8fedd68
Compare
8fedd68
to
064dade
Compare
This PR will configuration option for
multiline_parameters
so it's allowed to have like two params on the same line.