kotlinpoet
kotlinpoet copied to clipboard
Consider reversing the "wrap by default" behaviour
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.
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
One way to accomplish the same result could be to add an option to KotlinPoet that would enable or disable this behaviour.
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).
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.