-
Notifications
You must be signed in to change notification settings - Fork 288
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
Wrap supertypes if primary constructor wraps #1866
Conversation
This means there's always a ") : " on a line which prefixes the supertypes, so force them to also wrap to multiple lines.
|public enum class Roshambo( | ||
| private val handPosition: String, | ||
|) : Runnable, | ||
| Cloneable { | ||
| SCISSORS("peace sign"), |
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.
ktlint wants this to be
|public enum class Roshambo( | |
| private val handPosition: String, | |
|) : Runnable, | |
| Cloneable { | |
| SCISSORS("peace sign"), | |
|public enum class Roshambo( | |
| private val handPosition: String, | |
|) : Runnable, | |
| Cloneable { | |
| SCISSORS("peace sign"), |
which I absolutely hate. Visually there's no delineation between the supertypes and the body.
We could force a leading newline and do
|public enum class Roshambo( | |
| private val handPosition: String, | |
|) : Runnable, | |
| Cloneable { | |
| SCISSORS("peace sign"), | |
|public enum class Roshambo( | |
| private val handPosition: String, | |
|) : Runnable, | |
| Cloneable { | |
| | |
| SCISSORS("peace sign"), |
which ktlint allows. It's not great, but I'd be okay with this.
Thoughts? We could also just keep what I've already done. Most people aren't formatting generated code and I prefer mine best.
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 code style suggests that all supertypes should have the same indentation, so I think it's a bug in ktlint? I also prefer it this way, so let's keep it as is.
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.
They only mention horizontal alignment when you make a line break after the colon for non-primary constrictor cases.
The example with a wrapping primary constructor only aligns because they are doing a 4-space indent. So unfortunately I think ktlint is correct in what it does.
That being said, we can still leave it.
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 example with a wrapping primary constructor only aligns because they are doing a 4-space indent.
Good point.
|public enum class Roshambo( | ||
| private val handPosition: String, | ||
|) : Runnable, | ||
| Cloneable { | ||
| SCISSORS("peace sign"), |
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 code style suggests that all supertypes should have the same indentation, so I think it's a bug in ktlint? I also prefer it this way, so let's keep it as is.
|import java.util.AbstractSet | ||
|import kotlin.Comparable | ||
| | ||
|public abstract class Taco() : AbstractSet<Food>(), Serializable, Comparable<Taco> |
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.
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 want an API like
val mark = codeWriter.mark()
val originalLine = codeWriter.lineNumber
// Do normal write
if (codeWriter.lineNumber > originalLine) {
codeWriter.reset(mark)
// Do wrapped write
}
Would be useful for so many constructs. Probably even deserves a helper function that just takes two lambdas.
This means there's always a ") : " on a line which prefixes the supertypes, so force them to also wrap to multiple lines.
I decided to take a more opinionated approach that wasn't based on count, but instead is based on whether the primary constructor wraps to multiple lines. Closes #1865.
docs/changelog.md
has been updated if applicable.