tnorbye / kdoc-formatter

Reformats Kotlin KDoc comments, reflowing text and other cleanup, both via IDE plugin and command line utility
Apache License 2.0
73 stars 2 forks source link

How can I cancel the line indent #93

Closed SakurajimaMaii closed 4 months ago

SakurajimaMaii commented 1 year ago

Taking the screenshot as an example, is there a way for me to cancel the indentation of the line before aaaaaaa? image This is what I expected image

tnorbye commented 4 months ago

Yes, that's the "hanging indent"; you can use --hanging-indent=0

daniel-huss commented 4 months ago

Hi, since KDoc is Markdown by default, an indentation of four or more spaces converts the line to a code block. I think it would make sense to disable leading spaces on line breaks entirely. I had to disable the IntelliJ plugin because of that.

tnorbye commented 4 months ago

since KDoc is Markdown by default, an indentation of four or more spaces converts the line to a code block.

That's not actually exactly how Markdown behaves; both full Markdown renderers (like the bundled Markdown renderer in IntelliJ, shown below), as well as Dokka itself (the tool which renders KDocs in HTML) properly handle this:

Screenshot 2024-07-04 at 09 31 33

However, IntelliJ's in-IDE KDoc preview renderer doesn't seem to use a full-blown markdown renderer, and among other things it misinterprets this. In fact, when the ktfmt team integrated kdoc-formatter into ktfmt as the new doc comment formatter, they changed the default indentation from 4 to 3, which works around this IntelliJ bug.

At the time I didn't change kdoc-formatter since I didn't want to cause needless diffs for people with existing codebases. But this issue has come up multiple times so I guess it's better to just change it. So, I've just released* version 1.6.4 which changes the default from 4 to 3 -- and I also made it possible to override it directly in the KDoc IDE settings (similar to the --hanging-indent command line flag.)

*: Well I've uploaded it to the plugin marketplace; it has to be manually verified before it's made available, which can take up to two business days. You can also download and install from the releases page here: https://github.com/tnorbye/kdoc-formatter/releases/tag/v1.6.4