ktfmt: @sample tags should not be moved within kdoc
Repro steps
java -cp /ssd/ssd5/androidx-main/prebuilts/androidx/external/com/facebook/ktfmt/0.44/ktfmt-0.44.jar:..all.jars com.facebook.ktfmt.cli.Main --kotlinlang-style myfile.kt
- Try to format the following file:
package androidx.compose.runtime.saveable
/**
* Remember the value produced by [init].
*
* It behaves similarly to [remember], but the stored value will survive the activity or process
* recreation using the saved instance state mechanism (for example it happens when the screen is
* rotated in the Android application).
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveable
*
* If you use it with types which can be stored inside the Bundle then it will be saved and
* restored automatically using [autoSaver], otherwise you will need to provide a custom [Saver]
* implementation via the [saver] param.
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableCustomSaver
*
* You can use it with a value stored inside [androidx.compose.runtime.mutableStateOf].
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableWithMutableState
*
* If the value inside the MutableState can be stored inside the Bundle it would be saved
* and restored automatically, otherwise you will need to provide a custom [Saver]
* implementation via an overload with which has `stateSaver` param.
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableWithMutableStateAndCustomSaver
*
* @param inputs A set of inputs such that, when any of them have changed, will cause the state to
* reset and [init] to be rerun
* @param saver The [Saver] object which defines how the state is saved and restored.
* @param key An optional key to be used as a key for the saved value. If not provided we use the
* automatically generated by the Compose runtime which is unique for the every exact code location
* in the composition tree
* @param init A factory function to create the initial value of this state
*/
@Composable
fun <T : Any> rememberSaveable(
vararg inputs: Any?,
saver: Saver<T, out Any> = autoSaver(),
key: String? = null,
init: () -> T
): T { TODO() }
Expected
No changes are made
Actual
ktfmt format command will move @param tags to be next to @sample with @sample at the end.
resulting in
/**
* Remember the value produced by [init].
*
* It behaves similarly to [remember], but the stored value will survive the activity or process
* recreation using the saved instance state mechanism (for example it happens when the screen is
* rotated in the Android application).
*
* @param inputs A set of inputs such that, when any of them have changed, will cause the state to
* reset and [init] to be rerun
* @param saver The [Saver] object which defines how the state is saved and restored.
* @param key An optional key to be used as a key for the saved value. If not provided we use the
* automatically generated by the Compose runtime which is unique for the every exact code
* location in the composition tree
* @param init A factory function to create the initial value of this state
* @sample androidx.compose.runtime.saveable.samples.RememberSaveable
*
* If you use it with types which can be stored inside the Bundle then it will be saved and restored
* automatically using [autoSaver], otherwise you will need to provide a custom [Saver]
* implementation via the [saver] param.
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableCustomSaver
*
* You can use it with a value stored inside [androidx.compose.runtime.mutableStateOf].
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableWithMutableState
*
* If the value inside the MutableState can be stored inside the Bundle it would be saved and
* restored automatically, otherwise you will need to provide a custom [Saver] implementation via an
* overload with which has `stateSaver` param.
*
* @sample androidx.compose.runtime.saveable.samples.RememberSaveableWithMutableStateAndCustomSaver
*/
@Composable
fun <T : Any> rememberSaveable(
vararg inputs: Any?,
saver: Saver<T, out Any> = autoSaver(),
key: String? = null,
init: () -> T
): T { TODO() }
Details
@sample tags are sensitive to their location within kdoc as that indicates that location where the documentation tool should insert the referenced code.
Using ktfmt 0.44
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (14 by maintainers)
Commits related to this issue
- Treat @sample tag as a paragraph when formatting Tested: Added unit test Also compiled the JAR and tested it running: ``` java -jar ./ktfmt-0.50-SNAPSHOT-jar-with-dependencies.jar --kotlinlang-styl... — committed to omarismail94/ktfmt by omarismail94 2 years ago
- Don't reorder @sample tag (#406) Summary: Some users place `sample` tags at the beginning (before any other tag). This conflicts with our fixed ordering of kdoc tags. Since there's good reason for t... — committed to facebook/ktfmt by deleted user 2 years ago
- Update dependency com.facebook:ktfmt to v0.50 (#1466) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com.facebook:ktfmt](https://togithub.com/faceb... — committed to slackhq/circuit by slack-oss-bot 2 years ago
- Update dependency com.facebook:ktfmt to v0.50 (#874) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com.facebook:ktfmt](https://togithub.com/facebo... — committed to slackhq/foundry by slack-oss-bot 2 years ago
- Update dependency com.facebook:ktfmt to v0.51 (#1502) [](https://renovatebot.com) This PR contains the following updates: | Packa... — committed to ZacSweers/CatchUp by renovate[bot] 2 years ago
Just created this release here https://github.com/facebook/ktfmt/releases/tag/v0.50
Closing issue, but please let us know if you are still facing issues
@davidtorosyan I think the change works ! Below are examples of the type of diffs Ive seen. If the line seperator can’t be re-added, when do you think you’d be able to release a new version with this change?
@sampleand Kdoc list now removed. Personally, I think it’s cleaner with the new line separating. Is there a way to get that back?@seeis now at the bottom - follows how renderer outputs htmlOur intended function was probably to have
Example usageabove the sample tag, not in the@seeblock. Excellent catch! We will fix this by making@sampleinlined so it outputs properly.