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

Fix indentation of website code snippets #13571

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

Alexendoo
Copy link
Member

Fixes #13568

Follow up to #13359, I didn't catch that it swapped the strip_prefix out for a trim but they aren't interchangeable here

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Oct 20, 2024

r? @Centri3

rustbot has assigned @Centri3.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 20, 2024
@@ -102,7 +102,9 @@ pub fn sanitize_explanation(raw_docs: &str) -> String {
// Remove tags and hidden code:
let mut explanation = String::with_capacity(128);
let mut in_code = false;
for line in raw_docs.lines().map(str::trim) {
for line in raw_docs.lines() {
let line = line.strip_prefix(' ').unwrap_or(line);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent will still be removed with this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It removes the single space ///[here]text, strip_prefix does not remove multiple elements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arf indeed, thought it was stripping as long as it found the character. But then it creates an unbalance in case you have no whitespace character at the beginning of all lines (for whatever reason) and you then have a block.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah though this is exactly how the procedural macro did it as well. I think this (there being no space) is a non-issue overall but if this was already fixed in your PR I think that's a better way of doing it, afaik both rustfmt and clippy never catch this likely typo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which procedural macro?

Also, I think it's about handling the fact that most of the time, you write code after a whitespace (/// bla instead of ///bla). It's handled in rustdoc by finding out what's the minimum indent and then stripping according to that. Hum, might be worth to do that actually. Gonna update my PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the prior PR, declare_clippy_lint was turned from a procedural macro into a declarative macro. It had the same logic before as this PR has

Copy link
Member

@flip1995 flip1995 Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution better, as when copying the code block from the Clippy documentation, you don't have the leading in every line.

I don't think the non-leading whitespace in documentation is a concern, as ... we should just not do this in our documentation 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - didn't realize it'd leave a leading space. The issue was about it being unintentional, and hard to spot, rather than a style choice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, might be worth to do that actually. Gonna update my PR.

I don't think this is worth the effort/code. This is just to generate the Clippy documentation from the lint documentation in the Clippy code base. This code doesn't have to handle all possible doc writing styles people come up with, like rustdoc does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can't reuse the fns rustdoc uses here unlike for our lints since we only get them as strings, but I think it's fine to assume our docs are reasonably formatted

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Oct 23, 2024

Funnily enough, we worked on the same problem. I opened #13596 to fix it. However, I think this PR is not fixing since it still trims the indent if there is some.

EDIT: As discussed above, this solution seems to be the best out of the two.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @Centri3 I'll let you r+ as the assignee if you're also happy with the PR :)

@Centri3
Copy link
Member

Centri3 commented Oct 26, 2024

Would approve a way to either catch/fix wrongly formatted lints. It's a reasonable thing to ignore though. @bors r+

@bors
Copy link
Contributor

bors commented Oct 26, 2024

📌 Commit 2666ed6 has been approved by Centri3

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 26, 2024

⌛ Testing commit 2666ed6 with merge 3caff99...

@bors
Copy link
Contributor

bors commented Oct 26, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Centri3
Pushing 3caff99 to master...

@bors bors merged commit 3caff99 into rust-lang:master Oct 26, 2024
8 checks passed
@Alexendoo Alexendoo deleted the website-code-indent branch October 27, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

website: lint list: no indentation in code snippets
6 participants