ktfmt
ktfmt copied to clipboard
KtFmt infers with KotlinX Knit
When using KtFmt (Google style) together with KotlinX Knit tool it reports incorrectly formatted code for markers for Knit inside KDocs.
Execution failed for task ':spotlessKotlinCheck'.
> The following files had format violations:
src/main/kotlin/com/github/nomisRev/kafka/AdminSettings.kt
@@ -54,8 +54,7 @@
·*···}
·*·}
·*·```
-·*·<!---·KNIT·example-admin-01.kt·-->
-·*·<!---·TEST·lines.isNotEmpty()·-->
+·*·<!---·KNIT·example-admin-01.kt·-->·<!---·TEST·lines.isNotEmpty()·-->
·*/
public·fun·Admin(settings:·AdminSettings):·Admin·=·Admin.create(settings.properties())
Run './gradlew :spotlessApply' to fix these violations.
Using KtFmt 0.30.0 through Spotless Gradle plugin.
Thanks for the report. Does Knit require these two <!--- --> to be in separate lines?
@cgrushko yes
Directives in markdown files must always start at the beginning of the line and have the following general format for single-line directives:
<!--- <directive> [<parameters>] -->
or the following format for multi-line directives:
<!--- <directive> [<parameters>]
<text>
-->
Is there any plan to address this?
What about an option to disable formatting comments/docs?
We're planning to integrate a new kdoc formatting engine: https://github.com/facebook/ktfmt/issues/339 IIRC we checked that it solves this issue specifically.
@cgrushko I think there was some regression here. When currently running KtFmt over my project it completely changes how my KDoc is formatted breaking Knit support completely.
I.e.
* <!--- INCLUDE
* import arrow.core.raise.ensure
* import arrow.exact.Exact
* import arrow.exact.ExactError
* import arrow.exact.exact
becoming
* <!--- INCLUDE
* import arrow.core.raise.ensure import arrow.exact.Exact import arrow.exact.ExactEither import
* arrow.exact.ExactError import arrow.exact.exact import arrow.exact.exactEither
Also @see seems to be moved inside of a ``kotlin code-fence. Sadly this prevents us from using KtFmt on all my OSS projects again 😞
v0.47 formats like this
/*
<!---·KNIT·example-admin-01.kt·-->
<!---·TEST·lines.isNotEmpty()·-->
* <!--- INCLUDE
* import arrow.core.raise.ensure
* import arrow.exact.Exact
* import arrow.exact.ExactError
* import arrow.exact.exact
* -->
*/
Looks fixed to me, but I don't know much about Knit so feel free to reopen if I'm missing something