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

doc_markdown: suggestion looks like double backticks needed #8002

Closed
birkenfeld opened this issue Nov 20, 2021 · 3 comments · Fixed by #8011
Closed

doc_markdown: suggestion looks like double backticks needed #8002

birkenfeld opened this issue Nov 20, 2021 · 3 comments · Fixed by #8011
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@birkenfeld
Copy link
Contributor

For example:

error: item in documentation is missing backticks
   --> src/tcp.rs:135:58
    |
135 |     /// closed immediately.  The route can be added from TwinCAT, or this
    |                                                          ^^^^^^^ help: try: ``TwinCAT``
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown

Since all "try" hints are already enclosed in backticks, we end up with double backticks in the suggestion, which looks like it could be actual markup (especially if you also use ReST).

I suggest to omit the backticks in the hint, leading to try: `TwinCAT` which together with the error text makes it obvious what is meant.

@birkenfeld birkenfeld added the C-bug Category: Clippy is not doing the correct thing label Nov 20, 2021
@xFrednet
Copy link
Member

Hey, the suggestion intentionally has two backticks to make the fix automatically applicable. Clippy suggests writing `TwinCAT` and rustc automatically adds the outer backtick. Maybe this could be improved by showing the suggestion with a single backtick in a help message, and then using span_suggestion_hidden() to suggest the update with backticks. This would make the message a bit cleaner.

@rustbot label -C-bug +C-enhancement +good-first-issue

@rustbot rustbot added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy and removed C-bug Category: Clippy is not doing the correct thing labels Nov 20, 2021
@birkenfeld
Copy link
Contributor Author

Thanks for the explanation, that makes sense.

I can try to do what you suggested. Is there a facility to test the automated update suggestions in addition to the compiler output uitests?

@xFrednet
Copy link
Member

xFrednet commented Nov 20, 2021

Sure, that would be wonderful. The lint is currently emitted here:

span_lint_and_sugg(
cx,
DOC_MARKDOWN,
span,
"item in documentation is missing backticks",
"try",
format!("`{}`", snippet_with_applicability(cx, span, "..", &mut applicability)),
applicability,
);

The span_lint_and_sugg would need to be replaced with an span_lint_and_then function. Clippy's uitest save the lint messages in an .stderr file and create a .fixed file where the suggestions are applied. The lint already has some test files for these cases. See: #7904

You can claim the issue by commenting @rustbot claim. Let me know if you have any questions 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants