Skip to content

Commit

Permalink
fix: redundant_test_prefix dogfooding
Browse files Browse the repository at this point in the history
  • Loading branch information
farazdagi committed Nov 19, 2024
1 parent 24aa783 commit eb06e26
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 34 deletions.
24 changes: 14 additions & 10 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,20 @@ define_Conf! {
/// exported visibility, or whether they are marked as "pub".
#[lints(pub_underscore_fields)]
pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PubliclyExported,
/// Whether to include functions outside of `#[cfg(test)]` in the linting process or not.
///
/// This option allows running the lint against the integration tests: test functions located
/// there are not inside a node marked with `#[cfg(test)]` annotation (although they are
/// still marked using `#[test]` annotation and thus can have redundant "test_" prefix).
#[lints(redundant_test_prefix)]
redundant_test_prefix_check_outside_cfg_test: bool = false,
/// What suffix to use to avoid function name collisions when `test_` prefix is removed.
///
/// If set to `"_works"`, the lint will suggest renaming `test_foo` to `foo_works`.
/// Suffix is added only when there is a collision with an existing function name,
/// otherwise just `test_` prefix is removed (and no suffix added).
#[lints(redundant_test_prefix)]
redundant_test_prefix_custom_suffix: String = String::from("_works"),
/// Whether to lint only if it's multiline.
#[lints(semicolon_inside_block)]
semicolon_inside_block_ignore_singleline: bool = false,
Expand Down Expand Up @@ -706,16 +720,6 @@ define_Conf! {
/// Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros.
#[lints(macro_metavars_in_unsafe)]
warn_unsafe_macro_metavars_in_private_macros: bool = false,
/// Whether to include integration tests in the linting process or not.
#[lints(redundant_test_prefix)]
redundant_test_prefix_in_integration_tests: bool = false,
/// What suffix to use to avoid function name collisions when `test_` prefix is removed.
///
/// If set to `"_works"`, the lint will suggest renaming `test_foo` to `foo_works`.
/// Suffix is added only when there is a collision with an existing function name,
/// otherwise just `test_` prefix is removed (and no suffix added).
#[lints(redundant_test_prefix)]
redundant_test_prefix_custom_suffix: String = String::from("_works"),
}

/// Search for the configuration file.
Expand Down
6 changes: 3 additions & 3 deletions clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ mod tests {
use super::*;

#[test]
fn test_parse_contents() {
fn parse_contents_works() {
static CONTENTS: &str = r#"
declare_clippy_lint! {
#[clippy::version = "Hello Clippy!"]
Expand Down Expand Up @@ -1006,7 +1006,7 @@ mod tests {
}

#[test]
fn test_usable_lints() {
fn usable_lints_works() {
let lints = vec![
Lint::new(
"should_assert_eq2",
Expand Down Expand Up @@ -1041,7 +1041,7 @@ mod tests {
}

#[test]
fn test_by_lint_group() {
fn by_lint_group_works() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/empty_with_brackets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod unit_test {
use super::*;

#[test]
fn test_has_no_ident_token() {
fn has_no_ident_token_works() {
let input = "{ field: u8 }";
assert!(!has_no_ident_token(input));

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/needless_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ mod test {

#[test]
#[rustfmt::skip]
fn test_erode_from_back() {
fn erode_from_back_works() {
let input = "\
{
let x = 5;
Expand All @@ -428,7 +428,7 @@ mod test {

#[test]
#[rustfmt::skip]
fn test_erode_from_back_no_brace() {
fn erode_from_back_no_brace() {
let input = "\
let x = 5;
let y = something();
Expand Down
22 changes: 11 additions & 11 deletions clippy_lints/src/tabs_in_doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,77 +152,77 @@ mod tests_for_get_chunks_of_tabs {
use super::get_chunks_of_tabs;

#[test]
fn test_unicode_han_string() {
fn unicode_han_string() {
let res = get_chunks_of_tabs(" \u{4f4d}\t");

assert_eq!(res, vec![(4, 5)]);
}

#[test]
fn test_empty_string() {
fn empty_string() {
let res = get_chunks_of_tabs("");

assert_eq!(res, vec![]);
}

#[test]
fn test_simple() {
fn simple() {
let res = get_chunks_of_tabs("sd\t\t\taa");

assert_eq!(res, vec![(2, 5)]);
}

#[test]
fn test_only_t() {
fn only_t() {
let res = get_chunks_of_tabs("\t\t");

assert_eq!(res, vec![(0, 2)]);
}

#[test]
fn test_only_one_t() {
fn only_one_t() {
let res = get_chunks_of_tabs("\t");

assert_eq!(res, vec![(0, 1)]);
}

#[test]
fn test_double() {
fn double() {
let res = get_chunks_of_tabs("sd\tasd\t\taa");

assert_eq!(res, vec![(2, 3), (6, 8)]);
}

#[test]
fn test_start() {
fn start() {
let res = get_chunks_of_tabs("\t\taa");

assert_eq!(res, vec![(0, 2)]);
}

#[test]
fn test_end() {
fn end() {
let res = get_chunks_of_tabs("aa\t\t");

assert_eq!(res, vec![(2, 4)]);
}

#[test]
fn test_start_single() {
fn start_single() {
let res = get_chunks_of_tabs("\taa");

assert_eq!(res, vec![(0, 1)]);
}

#[test]
fn test_end_single() {
fn end_single() {
let res = get_chunks_of_tabs("aa\t");

assert_eq!(res, vec![(2, 3)]);
}

#[test]
fn test_no_tabs() {
fn no_tabs() {
let res = get_chunks_of_tabs("dsfs");

assert_eq!(res, vec![]);
Expand Down
8 changes: 4 additions & 4 deletions clippy_utils/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ mod test {
use super::reindent_multiline;

#[test]
fn test_reindent_multiline_single_line() {
fn reindent_multiline_single_line() {
assert_eq!("", reindent_multiline("".into(), false, None));
assert_eq!("...", reindent_multiline("...".into(), false, None));
assert_eq!("...", reindent_multiline(" ...".into(), false, None));
Expand All @@ -754,7 +754,7 @@ mod test {

#[test]
#[rustfmt::skip]
fn test_reindent_multiline_block() {
fn reindent_multiline_block() {
assert_eq!("\
if x {
y
Expand All @@ -779,7 +779,7 @@ mod test {

#[test]
#[rustfmt::skip]
fn test_reindent_multiline_empty_line() {
fn reindent_multiline_empty_line() {
assert_eq!("\
if x {
y
Expand All @@ -796,7 +796,7 @@ mod test {

#[test]
#[rustfmt::skip]
fn test_reindent_multiline_lines_deeper() {
fn reindent_multiline_lines_deeper() {
assert_eq!("\
if x {
y
Expand Down
6 changes: 3 additions & 3 deletions rustc_tools_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod test {
use super::*;

#[test]
fn test_struct_local() {
fn struct_local() {
let vi = get_version_info!();
assert_eq!(vi.major, 0);
assert_eq!(vi.minor, 4);
Expand All @@ -187,13 +187,13 @@ mod test {
}

#[test]
fn test_display_local() {
fn display_local() {
let vi = get_version_info!();
assert_eq!(vi.to_string(), "rustc_tools_util 0.4.0");
}

#[test]
fn test_debug_local() {
fn debug_local() {
let vi = get_version_info!();
let s = format!("{vi:?}");
assert_eq!(
Expand Down
6 changes: 6 additions & 0 deletions tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior
redundant-test-prefix-check-outside-cfg-test
redundant-test-prefix-custom-suffix
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
Expand Down Expand Up @@ -145,6 +147,8 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior
redundant-test-prefix-check-outside-cfg-test
redundant-test-prefix-custom-suffix
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
Expand Down Expand Up @@ -232,6 +236,8 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
msrv
pass-by-value-size-limit
pub-underscore-fields-behavior
redundant-test-prefix-check-outside-cfg-test
redundant-test-prefix-custom-suffix
semicolon-inside-block-ignore-singleline
semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
Expand Down

0 comments on commit eb06e26

Please sign in to comment.