pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

Add copy/paste enable/disable lines for each rule #2700

Closed nikclayton closed 2 weeks ago

nikclayton commented 2 weeks ago

Sorry, not a bug, but there wasn't a template for "Documentation change".

At the moment each rule entry in the documentation has a section at the bottom that lists the rule name and rule set.

For example, https://pinterest.github.io/ktlint/latest/rules/standard/#class-signature ends with:

Rule id: class-signature (standard rule set)

The only time I need this information is when I'm updating .editorconfig to enable or disable the rule. So it would be a helpful quality-of-life improvement if the system that generates the documentation could also insert a section with copy/pasteable strings that can be used directly. Bonus points if there's a "Copy" button I can use to copy the content directly.

paul-dingemans commented 2 weeks ago

Actually that was a good idea. It makes the documentation more easy to read.

nikclayton commented 1 week ago

2702 doesn't resolve this issue.

Now the text looks like e.g., standard:class-signature.

I can't copy/paste that in to a .editorconfig file, it needs to be ktlint_standard_class-signature = disabled.

So the generated HTML should look something like this:

<p><code>.editorconfig</code>: <code>ktlint_standard_class-signature = disabled</code> <button onclick="navigator.clipboard.writeText('ktlint_standard_class-signature = disabled')">Copy</button></p>
paul-dingemans commented 1 week ago

Bonus points if there's a "Copy" button I can use to copy the content directly.

I have improved the solution to support copy to clipboard in #2705. Instead of a single click, you will need two clicks. As the rules documentation is stored in Markdown files, and via Mkdocs is converted to Html, it was not possible to go with your solution.