Skip to content
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

Empty line before closing function parenthesis #1224

Closed
BraisGabin opened this issue Sep 2, 2021 · 4 comments · Fixed by #1868
Closed

Empty line before closing function parenthesis #1224

BraisGabin opened this issue Sep 2, 2021 · 4 comments · Fixed by #1868

Comments

@BraisGabin
Copy link

Expected Behavior

val a = foo(
  something = "a",
  another = "b",

)

The empty line between the last argument and the closing parenthesis should not be allowed.

val a = foo(
  something = "a",
  another = "b",
// this line
)

Observed Behavior

It is allowed

Your Environment

  • Version of ktlint used: 0.41.0 & 0.42.1
@BraisGabin
Copy link
Author

The same hapens with constructors:

class A(
  val a: String,
  val b: String

)

or with annotations:

@Component(
    modules = [
        A::class
    ],
    dependencies = [
        B::class,
    ]

)

@paul-dingemans
Copy link
Collaborator

This should be marked as an enhancement.

Currently no rule exists that prevent blank lines in elements of type list:
SUPER_TYPE_LIST
TYPE_ARGUMENT_LIST
TYPE_CONSTRAINT_LIST
TYPE_PARAMETER_LIST
VALUE_ARGUMENT_LIST
VALUE_PARAMETER_LIST

For remaining list types in the ElementType class it needs to be investigated the same applies to this type of element:
FILE_ANNOTATION_LIST
IMPORT_LIST
INITIALIZER_LIST
MODIFIER_LIST

@paul-dingemans
Copy link
Collaborator

There is no rule for this. Also I doubt that this is a violation of the Kotlin Coding conventions or Android Kotlin Style Guide. The latter one is a bit more explicit about vertical whitespace but does not seem to encourage or discourage it. But, I think that a blank line between the opening parenthesis and the first parameter as well as blank line between the last parameter and the closing parenthesis should be seen as redundant. Blank line between parameters can be useful for grouping related parameters.

As the style guides do not explicitly encourage/discourage blank lines in the argument lists, this behavior will only be added to the new code style ktlint_official which is to be released in a future version.

@paul-dingemans
Copy link
Collaborator

Blank lines betwee FILE_ANNOTATION_LIST and IMPORT_LIST will not be reported as those elements are unrelated. For INITIALIZER_LIST I was not able to find any example code and as of that I can not examine the structure of the element. The MODIFIER_LIST is already handled by modifier-list-spacing-rule.

paul-dingemans added a commit that referenced this issue Mar 18, 2023
…l` code style

This rule disallows blank lines to be used in super type lists, type argument lists, type constraint lists, type parameter lists, value argument lists, and value parameter lists.

Closes #1224
Closes #1781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants