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

Unpaired ``` not gracefully handled #235

Closed
bethcutler opened this issue May 17, 2021 · 5 comments
Closed

Unpaired ``` not gracefully handled #235

bethcutler opened this issue May 17, 2021 · 5 comments

Comments

@bethcutler
Copy link
Contributor

Original code; triple quote is unpaired accidentally

/**
 * ```kotlin
 * class foo {
 * }
 */

After formatting; an even # of triple quotes are added, which does nothing to solve the problem. Every time formatter is run, more triple quotes are added.

/**
 * ```kotlin
 * ```
 * ```
 * class foo { }
 * ```
 * ```
 */
@bethcutler
Copy link
Contributor Author

Here's a similar example, in which the triple quotes are not unpaired:

Before:

  /**
   * Title ```block```.
   * More text.
   */

After formatting once:

  /**
   * Title ```block```.
   * ```
   * ```
   * More text.
   * ```
   * ```
   */

Each time the file is formatted, 2 more lines of triple quotes are added before and after.

@bethcutler
Copy link
Contributor Author

I started looking into this, and it looks like the problem stems from kdoc lexer tagging whatever token follows "block." as a CODE_BLOCK_TEXT token, which I would assume is a bug.

Not sure if we can fix kdoc lexer. But also not sure what an appropriate workaround would be.

facebook-github-bot pushed a commit that referenced this issue Jun 6, 2021
)

Summary:
Fix for #235 and #221

Pull Request resolved: #238

Test Plan: ktfmt-diff: D28778163

Differential Revision: D28778136

Pulled By: cgrushko

fbshipit-source-id: 67ab94fd876a0030cff8f9969c819882da590bf2
@bethcutler
Copy link
Contributor Author

bethcutler commented Jan 20, 2022

Update: the first issue is indeed fixed, but the second case is still not ideal.

Original:

/**
 * Title ```block```.
 * More text.
 */

Formatted:

/**
 * Title
 * ```block```.
 * More text.
 * ```
 */

Adding a new triple quote seems wrong in this case. That said, this is likely a poor usage of Markdown where single backticks would be better.

@ZacSweers
Copy link

Just ran into this today as well, happy to share more repro cases

tnorbye added a commit to tnorbye/kdoc-formatter that referenced this issue Jul 7, 2022
(But not the comments. There isn't a way to turn that
off with ktfmt, so manually run kdocformat afterwards,
and remove any damaged comments such as extra ``` due
to facebook/ktfmt#235

(This also means you should run ./gradlew test, not check,
since the test target applies formatting that doesn't
match the sources.)

To format, run
   ./gradlew ktfmtFormat
tnorbye added a commit to tnorbye/kdoc-formatter that referenced this issue Jul 8, 2022
(But not the comments. There isn't a way to turn that
off with ktfmt, so manually run kdocformat afterwards,
and remove any damaged comments such as extra ``` due
to facebook/ktfmt#235

I couldn't find a way to have the ktfmt plugin applied
(so I can run the format task) without it also on its
own adding itself into the check task, which means
check now fails (because the sources don't match ktfmts
attempt to format comments too), so for now I've
commented out the tasks from the build file.

To format, put these back, then run
   ./gradlew ktfmtFormat
pulling-star pushed a commit to pulling-star/kotlin-doc_pro that referenced this issue Feb 5, 2024
(But not the comments. There isn't a way to turn that
off with ktfmt, so manually run kdocformat afterwards,
and remove any damaged comments such as extra ``` due
to facebook/ktfmt#235

I couldn't find a way to have the ktfmt plugin applied
(so I can run the format task) without it also on its
own adding itself into the check task, which means
check now fails (because the sources don't match ktfmts
attempt to format comments too), so for now I've
commented out the tasks from the build file.

To format, put these back, then run
   ./gradlew ktfmtFormat
@hick209
Copy link
Contributor

hick209 commented May 3, 2024

v0.49 formats

/**
 * Title ```block```.
 * More text.
 */

to this:

/** Title ```block```. More text. */

Which seems to me like the issue has been fixed.
Feel free to reopen if I'm missing something

@hick209 hick209 closed this as completed May 3, 2024
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

3 participants