astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.58k stars 1.09k forks source link

`config`'s default output format might not render as expected #12960

Open InSyncWithFoo opened 2 months ago

InSyncWithFoo commented 2 months ago

Currently, the output of a config command is something like this:

>>> subprocess.getoutput(['ruff', 'config', 'lint.preview'])
'Whether to enable preview mode. When preview mode is enabled, Ruff will\nuse unstable rules and fixes.\n\nDefault value: false\nType: bool\nExample usage:\n```toml\n# Enable preview features.\npreview = true\n```'

In the terminal, this looks nice:

Whether to enable preview mode. When preview mode is enabled, Ruff will
use unstable rules and fixes.

Default value: false
Type: bool
Example usage:
```toml
# Enable preview features.
preview = true

However, when rendered, the "Default value", "Type" and "Example usage" lines are collapsed into a single `<p>` ([Commonmark dingus](https://spec.commonmark.org/dingus/?text=Whether%20to%20enable%20preview%20mode.%20When%20preview%20mode%20is%20enabled%2C%20Ruff%20will%0Ause%20unstable%20rules%20and%20fixes.%0A%0ADefault%20value%3A%20false%0AType%3A%20bool%0AExample%20usage%3A%0A%60%60%60toml%0A%23%20Enable%20preview%20features.%0Apreview%20%3D%20true%0A%60%60%60)):

```html
<p>Whether to enable preview mode. When preview mode is enabled, Ruff will
use unstable rules and fixes.</p>
<p>Default value: false
Type: bool
Example usage:</p>
<pre><code class="language-toml"># Enable preview features.
preview = true
</code></pre>

For example, here's how PyCharm renders it:

A possible fix is to append two spaces to the end of the first two lines in question (Commonmark dingus):

'...Default value: false  \nType: bool  \nExample usage:...'

Also, default values and types should be surrounded in backticks.

Avasam commented 2 months ago

Note: Backslashes also work as markdown newline indicators (and are more obvious than double spaces) demo. But if the goal is to also display the same string in a terminal, then yeah two spaces is probably the best.

MichaReiser commented 2 months ago

Thanks for opening this issue. I agree, the output in PyCharm isn't ideal.

I assume that the hover text in PyCharm comes from the JSON schema. If that's the case, I would prefer a local change in the schema generation to use \ over the somewhat obscure use of two spaces at the end of the line.

InSyncWithFoo commented 2 months ago

It wasn't the schema (it would have been great if that was the case, though); I triggered the renderer semi-manually. (Yes, I could have asked for the JSON and put it together myself, too, but that's beside the point.)

Submitting a PR.

charliermarsh commented 2 months ago

@MichaReiser -- Is there still something to do here given the PR was closed?

MichaReiser commented 2 months ago

ruff config only supports the output format text and json. The ask in this issue is to add a markdown output format.

InSyncWithFoo commented 2 months ago

It turned out that the format wasn't as nice compared to other popups of the same kind, so I rendered it manually anyway. It took more efforts than I expected, but behold the result:

I'll keep this issue open, though, since someone else might need it.

MichaReiser commented 2 months ago

This looks great!