Skip to content

validate lint name in clippy_dev #10817

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

Merged
merged 3 commits into from
May 24, 2023
Merged

Conversation

y21
Copy link
Member

@y21 y21 commented May 23, 2023

This PR adds a little bit of validation to cargo dev new_lint. I've had it happen a few times where I wanted to add a new lint, but forgot that lint names cannot contain -. If you try to do it anyway, clippy_dev will generate illegal syntax (like adding mod test-lint; to clippy_lints/src/lib.rs for the module declaration). Maybe having it error out early would be helpful to others too.

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2023

r? @dswij

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 23, 2023
.required(true)
.value_parser(|name: &str| {
if name.contains('-') {
Err("Lint name cannot contain `-`, use `_` instead.")
Copy link
Member

@flip1995 flip1995 May 24, 2023

Choose a reason for hiding this comment

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

Instead of error, would it make sense to just replace - with _? I don't think there ever is a use case where you want -.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense to me (assuming that was directed at me). I think it's safe to assume that the user probably didn't want the literal character - but just meant to have it as a delimiter and replacing it with _ is fine

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that question was for you :)

Co-authored-by: Philipp Krones <[email protected]>
@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented May 24, 2023

📌 Commit c70f2a2 has been approved by flip1995

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 24, 2023

⌛ Testing commit c70f2a2 with merge b6284f0...

@bors
Copy link
Contributor

bors commented May 24, 2023

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

@bors bors merged commit b6284f0 into rust-lang:master May 24, 2023
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.

5 participants