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

Wrap language constructs which can not be used as expressions #1097

Closed
gchallen opened this issue Mar 8, 2021 · 2 comments
Closed

Wrap language constructs which can not be used as expressions #1097

gchallen opened this issue Mar 8, 2021 · 2 comments
Labels
Milestone

Comments

@gchallen
Copy link

gchallen commented Mar 8, 2021

Expected Behavior

ktlint should not pass code like this:

class Course(var number: String) { fun changeNumber(newNumber: String) { number = newNumber } }

which is much clearer written:

class Course(var number: String) {
  fun changeNumber(newNumber: String) {
    number = newNumber
  }
}

(Yes, I know that this is a dumb example. But you get the drift.)

Current Behavior

At least with the ruleset that I have enabled the code above is accepted without errors, until you hit the line limit if there is one.

I'm curious about whether this is on the roadmap or considered out of scope for ktlint.

Additional information

  • Current version of ktlint: 0.40.0
@paul-dingemans
Copy link
Collaborator

This rule is stated to generic to be picked up. But at minimum, wrapping has to be enforced in following cases:

  • package
  • import
  • type_alias
  • classes
  • functions
  • control loops which can not be used as expression:
    • for loop
    • while
    • do-while

@paul-dingemans paul-dingemans changed the title Enforce Newlines for Readability Wrap language constructs which can not be used as expressions Apr 16, 2023
@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Apr 16, 2023
@paul-dingemans
Copy link
Collaborator

ktlint should not pass code like this:

class Course(var number: String) { fun changeNumber(newNumber: String) { number = newNumber } }

This is mostly covered by #2001. Other constructs can only be placed on same line when separated by ; which will be covered by #1078. Issue is closed as duplicate.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants