You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example, the // body sits against the header. There are other examples in class signature code samples.
No blank lines in list
classFooBar :
Foo,
Bar {
// body
}
In this example, body sits against the class header. I would call this a "long" class header as it's multi-line.
I note that this proposal conflicts with "No empty first line at start in class body" so would have to be disabled or enabled only in part when ktlint_official rule style is used.
Steps to Reproduce
Your Environment
Version of ktlint used:
Relevant parts of the .editorconfig settings
Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
Version of Gradle used (if applicable):
Operating System and version:
The text was updated successfully, but these errors were encountered:
Ktlint indeed does not comply with Kotlin Coding Conventions in this regard. Allowing the first line in a class to be blank is not consistent with disallowing the first line in a function to be blank. Also, it would be inconsistent to allow a blank line as first line in the class, but disallowing a blank line as last line in the class. Wrapping the opening brace to a separate line is not consistent with the way braces are used in all other block like situations.
Let's move this issue to the discussion section about ktlint configurability. Maybe the rule no-empty-class-body can be replaced with a new rule that allows following options:
Disallow blank line at start of class
Enforce blank line at start of class
Enforce blank line at start of class for long class header only
Wrap opening curly brace for long class header only
Expected Behavior
Class header & body are separated after a long class header. Compliant examples from Kotlin coding conventions:
In the above example, there is a blank line between the opening brace and the class body.
In the above example, there is no blank line between the opening brace and the class body, but the opening brace is on its own line.
ktlint should enforce this rule.
Observed Behavior
As far as I can tell, ktlint does not support this. Some non-compliant examples from the docs (dev-snapshot) follow.
Class signature
In this example, the
// body
sits against the header. There are other examples in class signature code samples.No blank lines in list
In this example, body sits against the class header. I would call this a "long" class header as it's multi-line.
I note that this proposal conflicts with "No empty first line at start in class body" so would have to be disabled or enabled only in part when ktlint_official rule style is used.
Steps to Reproduce
Your Environment
.editorconfig
settingsThe text was updated successfully, but these errors were encountered: