rust/clippy_utils/src
Samuel Tardieu 8eed35023f
New lint: redundant_test_prefix (#13710)
This PR has started as an effort to proceed from the feedback in
rust-lang/rust-clippy#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 rust-lang/rust-clippy#8931

changelog: new lint: [`redundant_test_prefix`]
2025-04-16 06:15:18 +00:00
..
ast_utils Merge remote-tracking branch 'upstream/master' into rustup 2025-04-03 21:31:02 +02:00
mir fix: redundant_clone FP on enum cast (#14395) 2025-03-21 14:23:52 +00:00
ty Apply collapsible_if to Clippy itself 2025-03-27 14:40:44 +01:00
attrs.rs Merge commit '609cd310be' into clippy-subtree-update 2024-12-26 15:15:54 +01:00
check_proc_macro.rs Move hir::Item::ident into hir::ItemKind. 2025-03-18 06:29:50 +11:00
comparisons.rs Merge commit 'd9c24d1b1e' into clippyup 2023-07-17 10:22:32 +02:00
consts.rs Don't use f16 and f128 directly in clippy_utils 2025-04-03 02:00:27 +01:00
diagnostics.rs Apply collapsible_if to Clippy itself 2025-03-27 14:40:44 +01:00
eager_or_lazy.rs Fix clippy 2025-03-06 17:58:32 -03:00
higher.rs Apply collapsible_if to Clippy itself 2025-03-27 14:40:44 +01:00
hir_utils.rs Take advantage of match ergonomics in clippy_utils::hir_utils 2025-03-29 12:04:23 +01:00
lib.rs new lint: redundant_test_prefix 2025-04-15 14:42:09 +03:00
macros.rs Move methods from Map to TyCtxt, part 5. 2025-04-02 10:00:46 +11:00
msrvs.rs Various fixes for manual_is_power_of_two (#14463) 2025-04-14 22:56:38 +00:00
numeric_literal.rs Merge commit '51d49c1ae2' into clippy-subtree-update 2025-01-28 19:33:54 +01:00
paths.rs Add new lint manual_dangling_ptr 2025-03-23 13:48:01 -07:00
ptr.rs Move some Map methods onto TyCtxt. 2025-02-17 13:21:02 +11:00
qualify_min_const_fn.rs Merge commit '1e5237f4a5' into clippy-subtree-update 2025-03-20 22:34:29 +01:00
source.rs Make collapsible_if recognize the let_chains feature (#14481) 2025-03-28 09:17:24 +00:00
str_utils.rs Fix various typos in lint messages, descriptions and comments 2025-03-24 16:04:32 +01:00
sugg.rs Merge remote-tracking branch 'upstream/master' into rustup 2025-04-03 21:31:02 +02:00
sym_helper.rs Merge commit '928e72dd10' into clippyup 2021-02-25 11:25:22 +01:00
usage.rs Apply collapsible_if to Clippy itself 2025-03-27 14:40:44 +01:00
visitors.rs Apply collapsible_if to Clippy itself 2025-03-27 14:40:44 +01:00