Skip to content

Warn on // tidy-ignore-linelength #130984

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

Closed
jieyouxu opened this issue Sep 28, 2024 · 5 comments · Fixed by #135421
Closed

Warn on // tidy-ignore-linelength #130984

jieyouxu opened this issue Sep 28, 2024 · 5 comments · Fixed by #135421
Labels
A-tidy Area: The tidy tool C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Sep 28, 2024

I've ran into this many times, where I tried to write

// tidy-ignore-linelength

or other tidy-ignore-* tidy directives. But this is actually wrong and does nothing, since the actual syntax is

// ignore-tidy-linelength

It might be helpful if tidy warns on seeing // tidy-ignore-linelength. It's not a big deal, just a minor papercut.

@jieyouxu jieyouxu added A-tidy Area: The tidy tool C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Sep 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 28, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 28, 2024
cod10129 added a commit to cod10129/rust that referenced this issue Jan 11, 2025
This fixes rust-lang#130984.
Tidy now warns on seeing the typo "tidy-ignore-[CHECK]" instead of "ignore-tidy-[CHECK]".
@cod10129
Copy link
Contributor

I implemented this warning here, and it warns on any appearance of the text tidy-ignore in the code. The error message I made looks like this:1

<snip>
tidy check
tidy error: rust-checkout-path\library\core\src\lib.rs:107: use ignore-tidy-[check], not tidy-ignore-[check]
some tidy checks failed
<snip>

where I inserted the line // tidy-ignore-linelength into library/core/src/lib.rs at line 107.

However, I still have a couple questions.
First, I don't really know where this code should go in tidy. I put it in style.rs inside check(), but I'm not familiar with tidy's code so I don't know what a good place for it would be.
Second, is there a place for tidy tests? I would think that I should add a test for this new functionality, but it doesn't look like tidy has tests anywhere. Am I missing something obvious?

Footnotes

  1. I would be fine with changing it

@jieyouxu
Copy link
Member Author

First, I don't really know where this code should go in tidy. I put it in style.rs inside check(), but I'm not familiar with tidy's code so I don't know what a good place for it would be.

That seems reasonable.

Second, is there a place for tidy tests? I would think that I should add a test for this new functionality, but it doesn't look like tidy has tests anywhere. Am I missing something obvious?

I think tidy is in general under-tested. It may be possible to slightly rework how the tidy ignore directives are handled to permit testing it against a provided string line without actually touching fs, but yeah.

cod10129 added a commit to cod10129/rust that referenced this issue Jan 12, 2025
Fixes rust-lang#130984.
Tidy now warns on seeing the typo "tidy-ignore-{CHECK}" (it's actually "ignore-tidy").
@onur-ozkan
Copy link
Member

How about checking if the word "tidy" has - as a prefix or suffix? If it does, tidy should expect it to be a valid directive. If it's unrecognized we could fail with an error message saying "unrecognized tidy directive". Because this could potentially happen with any other tidy-related directives as well.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jan 14, 2025

How about checking if the word "tidy" has - as a prefix or suffix? If it does, tidy should expect it to be a valid directive. If it's unrecognized we could fail with an error message saying "unrecognized tidy directive". Because this could potentially happen with any other tidy-related directives as well.

I think that would make sense yes. I don't quite recall what tidy directives exist.

I just mentioned the ignore-tidy vs tidy-ignore form because this form trips me up every time lol.

@cod10129
Copy link
Contributor

How about checking if the word "tidy" has - as a prefix or suffix? If it does, tidy should expect it to be a valid directive. If it's unrecognized we could fail with an error message saying "unrecognized tidy directive". Because this could potentially happen with any other tidy-related directives as well.

This was more complicated than I expected (tidy doesn't really have anywhere central to collect all the valid directives), so I made an implementation that only knows about the "ignore-tidy-FOO" directives used in style.rs and tidy-alphabetical-{start, end}. I ran ./x test tidy with my code and nothing violates the check in the repository, so it should be fine.
(I probably missed some checks that tidy accepts, but aren't used anywhere in the rust repo. Since there's no centralization in tidy, I couldn't really find them. Please tell me if they do exist.)

I've updated the PR #135421 with this change.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 17, 2025
…ozkan

Make tidy warn on unrecognized directives

This PR makes it so tidy warns on unrecognized directives, as recommended on [the discussion of rust-lang#130984](rust-lang#130984 (comment)). This is edited from the previous version of this PR, which only warned on "tidy-ignore" and no other tidy directive typos.

Fixes rust-lang#130984.

`@rustbot` label A-tidy C-enhancement
@bors bors closed this as completed in 8fec08b Jan 18, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 18, 2025
Rollup merge of rust-lang#135421 - cod10129:warn-tidy-ignore, r=onur-ozkan

Make tidy warn on unrecognized directives

This PR makes it so tidy warns on unrecognized directives, as recommended on [the discussion of rust-lang#130984](rust-lang#130984 (comment)). This is edited from the previous version of this PR, which only warned on "tidy-ignore" and no other tidy directive typos.

Fixes rust-lang#130984.

``@rustbot`` label A-tidy C-enhancement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants