Skip to content

New lint: redundant_test_prefix - #13710

Merged
samueltardieu merged 1 commit into
rust-lang:masterfrom
farazdagi:feat/redundant-test-prefix
Apr 16, 2025
Merged

samueltardieu merged 1 commit into
rust-lang:masterfrom
farazdagi:feat/redundant-test-prefix

Conversation

@farazdagi

@farazdagi farazdagi commented Nov 19, 2024 •

Copy link
Copy Markdown
Contributor

This PR has started as an effort to proceed from the feedback in #12861.

  • Checks test functions (functions marked with #[test] annotation) for redundant "test_" prefix.
  • Auto-fix is supported (and handles collisions gracefully, see below).
    • If removing "test_" prefix from, say, test_foo() results in a name collision (either because function foo() is already defined within the current scope, or because the foo() call exists within function -- thus creating an unwanted recursion), lint suggests function rename, warning the user that a simple trimming of test_ prefix will result in a name collision.
    • If removing "test_" prefix results in invalid identifier (consider test_const, test_, test_42), then again no auto-fix is suggested, user is asked to rename function, with a note that a simple prefix trimming will result in an invalid function name. (Applicability::HasPlaceholders is used and user is suggested to: drop test_ prefix + add _works suffix, i.e. test_foo becomes foo_works -- but again, user has to apply those changes manually).
    • If trimmed version of the function name is a valid identifier, doesn't result in name collision or unwanted recursion, then user is able to run auto-fix.

fixes #8931

changelog: new lint: [redundant_test_prefix]

@rustbot

rustbot commented Nov 19, 2024

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dswij (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 19, 2024
@farazdagi
farazdagi marked this pull request as ready for review November 19, 2024 21:37
@farazdagi

Copy link
Copy Markdown
Contributor Author

@dswij any ETA on when you'll be able to review (it has been more than 2 weeks -- so, I am not sure whether there needs to be some action on my part to get this rolling).

@farazdagi

Copy link
Copy Markdown
Contributor Author

@J-ZhengLi @xFrednet sorry to bother you, but maybe you'll have time to review this PR (since you've provided good feedback on its previous incarnation -- and I've incorporated your suggestions).

Really eager to receive my first feedback on this one (still learning the clippy's tooling), before diving into any other open tasks/issues.

@xFrednet

xFrednet commented Dec 13, 2024 •

Copy link
Copy Markdown
Contributor

Hej, thank you for the ping. Sure, I'll add it to my reviewing list. You should get some feedback this weekend!

@J-ZhengLi You're welcome to also help with the review if you want. But also don't feel any pressure :)

r? @xFrednet

@rustbot rustbot assigned xFrednet and unassigned dswij Dec 13, 2024
@rust-lang rust-lang deleted a comment from rustbot Dec 13, 2024

@xFrednet xFrednet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very solid start. Thank you for picking up the other PR, it's nice to see it being worked on! :D

Please let me know if you have any questions.

Comment thread clippy_config/src/conf.rs Outdated
Comment thread clippy_config/src/conf.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread tests/ui-toml/redundant_test_prefix/redundant_test_prefix.custom_suffix.fixed Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread tests/ui/redundant_test_prefix.rs
@xFrednet

Copy link
Copy Markdown
Contributor

I'm unassigning myself from this PR. @farazdagi if you want to continue this work, please request a new reviewer with r? clippy

@xFrednet xFrednet removed their assignment Mar 16, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 31, 2025
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch from eb06e26 to c89ac83 Compare April 5, 2025 13:10
@farazdagi
farazdagi marked this pull request as draft April 5, 2025 17:23
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch from 77b4636 to 11811d6 Compare April 8, 2025 10:55
@farazdagi
farazdagi marked this pull request as ready for review April 8, 2025 11:52
@farazdagi

Copy link
Copy Markdown
Contributor Author

Implemented suggestions from the review (thanks @xFrednet for great pointers)

r? clippy

@farazdagi

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 8, 2025
Comment thread clippy_utils/src/lib.rs Outdated
Comment thread clippy_utils/src/lib.rs Outdated
@Manishearth

Copy link
Copy Markdown
Member

r? @samueltardieu for now

@rustbot rustbot assigned samueltardieu and unassigned Manishearth Apr 8, 2025
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch from 10de1a6 to cc70493 Compare April 12, 2025 06:42

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is neater indeed without the configuration option.

I have some remarks left, about the style, it won't change anything in the uitest output.

Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Apr 12, 2025
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch from cc70493 to 3936d49 Compare April 15, 2025 08:20
@farazdagi
farazdagi requested a review from samueltardieu April 15, 2025 08:50
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 15, 2025

@samueltardieu samueltardieu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Almost there! Those latest comments are stylish issues, and some cleanups that could be done while you're editing this part of the code.

The only "performance" issue (and change proposal) is that it is more costly to intern things than to get their textual representation back, so it is best to intern only once.

Thanks for your patience.

Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_lints/src/redundant_test_prefix.rs Outdated
Comment thread clippy_utils/src/lib.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 15, 2025
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch 2 times, most recently from 7fe7a1b to 0efbe2b Compare April 15, 2025 11:27
@farazdagi

Copy link
Copy Markdown
Contributor Author

Almost there! Those latest comments are stylish issues, and some cleanups that could be done while you're editing this part of the code.

The only "performance" issue (and change proposal) is that it is more costly to intern things than to get their textual representation back, so it is best to intern only once.

Thanks for your patience.

No problem at all -- learning from this review process almost more than from the lint's implementation itself. So, thank you for such an insightful review.

@farazdagi
farazdagi requested a review from samueltardieu April 15, 2025 11:34
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 15, 2025

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like you missed this one. The rest looks good to me!

Comment thread clippy_utils/src/lib.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 15, 2025
@farazdagi
farazdagi force-pushed the feat/redundant-test-prefix branch from 0efbe2b to e2422a6 Compare April 15, 2025 11:42

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@rustbot label -S-waiting-on-author

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Apr 15, 2025
@samueltardieu
samueltardieu added this pull request to the merge queue Apr 16, 2025
@samueltardieu

Copy link
Copy Markdown
Member

Thanks @farazdagi. The new lint will likely appear in the nightly toolchain before the end of the week.

Merged via the queue into rust-lang:master with commit 8eed350 Apr 16, 2025
@farazdagi
farazdagi deleted the feat/redundant-test-prefix branch April 16, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test function name starts with test_

6 participants