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
Demo/proposal: FormattingFiler #664
Conversation
Inspired by GJF's implementation of the same name - this demos an implementation of a `FormattingFiler` that formats kotlin code with [KtLint](https://github.com/pinterest/ktlint) while writing. This could also be applicable to the other `writeTo()` overloads, but would require slightly different support. I _don't_ think this should be part of the first party KotlinPoet API, but it could be a useful extension artifact. This filer-only API alone may be more valid as an extension artifact on KtLint's project, but as mentioend above the implementation could be useful for other `writeTo()` overloads too. Example usage: ```kotlin val formattingFiler = filer.asFormatting() fileSpec.writeTo(formattingFiler) ```
For those who think kotlinc isn't slow enough? |
For those that generate models/etc in separate, heavily-cached non-gradle subprojects :) |
Agree that this shouldn't live in the main artifact, but we can definitely move this into a separate one. We do plan to improve Kotlinpoet's own formatting though. |
Do you want me to set up a separate artifact as part of this? Or discuss it further/separately first? |
I envision this to be more useful for consumers that are implementing possibly complex |
Yep, let's set up a separate artifact. |
@Egorand could you elaborate please? Do you plan to use Kotlin official formatting guide as a base or this is just a backlog idea that isn't put much thought into? |
@LouizFC KotlinPoet already produces reasonably well-formatted code, but there are some issues we're aware of, such as function and constructor signature not being formatted according to the official style guide. This issue specifically is a top priority and I'm hoping to address it soon, if there's anything else that doesn't work for you - please file bugs. |
I'd prefer to not fix our formatting bugs by introducing support for pluggable formatters. One thing we learned with Dagger 2 is that nobody wants to wait for a formatting step. |
Going to close this for now as I think the lack of any direct touch points with KotlinPoet means it probably should just be a separate project |
Inspired by GJF's implementation of the same name - this demos an implementation of a
FormattingFiler
that formats kotlin code with KtLint while writing. This could also be applicable to the otherwriteTo()
overloads, but would require slightly different support.I don't think this should be part of the first party KotlinPoet API, but it could be a useful extension artifact. This filer-only API alone may be more valid as an extension artifact on KtLint's project, but as mentioend above the implementation could be useful for other
writeTo()
overloads too.Example usage:
Possible other
writeTo()
overloads could beFileSpec.formattedWriteTo()
extension functions, but would likely want to reuse the directory preparation logic.Happy to also just put all this in a separate project and call it a day. Talked with @Egorand offline and wanted to give first refusal here :)