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

Consider reversing the "wrap by default" behaviour #1314

Open
Egorand opened this issue Jul 6, 2022 · 4 comments
Open

Consider reversing the "wrap by default" behaviour #1314

Egorand opened this issue Jul 6, 2022 · 4 comments
Milestone

Comments

@Egorand
Copy link
Collaborator

Egorand commented Jul 6, 2022

Treating all spaces as wrapping by default leads to shorter lines and better formatting overall, but in certain cases can break compilation (there's a large number of issues mentioning this problem). Using · addresses the problem, but it's not ergonomic:

  • · can't be typed on the keyboard, so it has to be copy-pasted from the docs.
  • The discoverability of this feature is low, people often learn about it only after they've generated uncompilable code. It's especially frustrating for developers who build libraries on top of KotlinPoet.
  • Having to use · feels like extra effort just to get the library to function properly, which breaks the rule of applying the least amount of effort to get correct results.

We used to have %W as a "wrapping space" format modifier prior to 1.0, which could be used optionally to improve the formatting of generated code. I suggest that we revert to something like this in 2.0.

@Egorand Egorand added this to the 2.0 milestone Jul 6, 2022
@slavonnet
Copy link

slavonnet commented Aug 26, 2023

i simple replace all spaces with · for generated classes. More elegant resolve is wil,l do Code Formating BEFORE write all class to file in Idea format way. In kotlin poer soft wrapper is stupid and all time brake compilation in long generated code

@pandaninjas
Copy link

One way to accomplish the same result could be to add an option to KotlinPoet that would enable or disable this behaviour.

@JakeWharton
Copy link
Member

I'll copy my comment from another issue I just closed as a duplicate of this one:

I'm not a huge fan of adding arbitrary options which create a ton of knobs, but in this case it would be an easy way to start getting this functionality in the hands of users (myself included).

@felixwiemuth
Copy link

I agree that wrapping by default should either be completely disabled, or this should be an option for the user (e.g. as an argument to FileSpec.builder(...)). My arguments are similar to the above, see details here: #1887. Mainly that it is easy to make mistakes and that therefore no wrapping should be the default, having to explicitly opt-in for the risky way.

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

No branches or pull requests

5 participants