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

tests: add test that roughly ensures that our lint messages conform with the diagnostics convention of the rustc dev guide #6787

Merged
merged 7 commits into from
Feb 28, 2021

Conversation

matthiaskrgr
Copy link
Member

lint message should not start with uppercase letters
lint messages should not have punctuation at the end of the last line

https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure

The test reads through all the .stderr files in the testsuit and checks lint messages that start with "help: ", "error: " etc.
There is also an exception list for special messages that are deemed acceptable.

changelog: make sure lint messages conform with the rustc dev guide and add test

@rust-highfive
Copy link

r? @llogiq

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 24, 2021
@matthiaskrgr
Copy link
Member Author

I wondered if we could have some kind of internal lint for this but there are too many different ways how we construct lint messages inside the code base.
Just checking all the the .stderr files seemed like the most straightforward way.

r"the compiler unexpectedly panicked. this is a bug.",
r".*help: I think you meant: .*",
r"Iterator.* will panic at runtime",
])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be more generalized? For Iterator::step_by(0), you could detect Captialized::word. For did you mean unix, you could detect the question mark. You can have a whitelist of proper noun first words like "I", "Intel" or "C-like". For multiple sentences, you can detect . Capitalized...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. I would rather have a false positive (let's say "Iterator::count() foo bla") trigger a CI failure just to be immediately added to the allowlist than have a false negative slip through because allow-list regex is too general.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm also fine with having a hardcoded list. (With my two comments applying to 4 messsages above addressed).

let exceptions_set: RegexSet = RegexSet::new(&[
r".*error: I see you're using a LinkedList! Perhaps you meant some other data structure?",
r".*C-like enum variant discriminant is not portable to 32-bit targets",
r".*Iterator::step_by(0) will panic at runtime",
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be an exceptions, but in backticks.

r".*remove .*the return type...",
r"note: Clippy version: .*",
r"the compiler unexpectedly panicked. this is a bug.",
r".*help: I think you meant: .*",
Copy link
Member

Choose a reason for hiding this comment

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

I also don't think we should use the first person in messages.

r"the compiler unexpectedly panicked. this is a bug.",
r".*help: I think you meant: .*",
r"Iterator.* will panic at runtime",
])
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm also fine with having a hardcoded list. (With my two comments applying to 4 messsages above addressed).

@bors
Copy link
Collaborator

bors commented Feb 26, 2021

☔ The latest upstream changes (presumably #6800) made this pull request unmergeable. Please resolve the merge conflicts.

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 26, 2021

rebased, I also hope I addressed all the lint review remarks in the change some lint messages and remove old entries from the ignorelist commit :)

])
.unwrap();

// sometimes the first character is capitalized and it is legal (like in "Iterator...") or
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The comment still has "Iterator", but this is a type which should be in backticks, so better use another example.

@llogiq
Copy link
Contributor

llogiq commented Feb 28, 2021

Apart from a very minuscule nit, this looks good. I like the idea of using the UI tests to check the messages.

…ith the diagnostics convention of the rustc dev guide

lint message should not start with uppercase letters
lint messages should not have punctuation at the end of the last line

https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure

The test reads through all the .stderr files in the testsuit and checks lint messages that start with "help: ", "error: " etc.
There is also an exception list for special messages that are deemed acceptable.

changelog: make sure lint messages conform with the rustc dev guide and add test
@llogiq
Copy link
Contributor

llogiq commented Feb 28, 2021

Thank you! @bors r+

@bors
Copy link
Collaborator

bors commented Feb 28, 2021

📌 Commit ebc5c8f has been approved by llogiq

@bors
Copy link
Collaborator

bors commented Feb 28, 2021

⌛ Testing commit ebc5c8f with merge ac2f041...

@bors
Copy link
Collaborator

bors commented Feb 28, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing ac2f041 to master...

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.

6 participants