Skip to content

Detect extra "base indentation" in Rust code blocks in docs #15025

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

Open
ojeda opened this issue Jun 9, 2025 · 2 comments
Open

Detect extra "base indentation" in Rust code blocks in docs #15025

ojeda opened this issue Jun 9, 2025 · 2 comments
Labels
A-lint Area: New lints

Comments

@ojeda
Copy link
Contributor

ojeda commented Jun 9, 2025

What it does

For Rust code blocks, and for code blocks in many other languages, it is very likely that extra indentation is not indented if it is applied across the entire contents of the code block, e.g. an extra space on all lines (or even just all non-empty lines).

Having said that, when/if rustfmt stabilizes formatting code blocks in documentation, this lint may not be needed anymore.

Possibly related, at least implementation-wise: #15023 and #15024.

Advantage

  • More consistency in docs.
  • Less time spent by reviewers.

Drawbacks

No response

Example

/// ```
///  fn f() {}
/// ```

Should be written as:

/// ```
/// fn f() {}
/// ```
@felix91gr
Copy link
Contributor

@ojeda small nitpick: I'd clarify that this is for code blocks inside of doc comments, in the title. That way it's easier to understand that this is not something that rustfmt already covers.

(I might just be me not used to the wording, but when I was reading this issue, I saw "code blocks" and I thought "but yeah, this is something rustfmt has had since forever")

BTW, has this need been talked about at the rustfmt repo / chat? It super feels to me like something under the sphere of rustfmt rather than clippy.

That being said, #13711 exists, so I bet this lint can easily be extended from that and then both can be deprecated after rustfmt addresses doc comment indentation

@ojeda ojeda changed the title Detect extra "base indentation" in Rust code blocks Detect extra "base indentation" in Rust code blocks in docs Jun 10, 2025
@ojeda
Copy link
Contributor Author

ojeda commented Jun 10, 2025

I'd clarify that this is for code blocks inside of doc comments, in the title.

Done, thanks!

BTW, has this need been talked about at the rustfmt repo / chat?

No, I didn't talk about it with rustfmt (nor rustdoc, for that matter). I think it would be nice to have a way to ping them in this sort of cross-issues (e.g. see #14402 (comment) for another case), since it is convenient to open new lint ideas in a single place and then "redirect them" (to compiler, rustdoc or rustfmt) if needed.

It super feels to me like something under the sphere of rustfmt rather than clippy.

Yeah, I agree that rustfmt may want to cover this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants