diff --git a/Cargo.toml b/Cargo.toml index a5fcc7a3197c2..a2ce59c7f4cca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ iter_on_single_items = "warn" unused_peekable = "warn" too_long_first_doc_paragraph = "warn" suspicious_operation_groupings = "warn" +redundant_clone = "warn" # cargo cargo = { level = "warn", priority = -1 } multiple_crate_versions = "allow" diff --git a/apps/oxlint/src/output_formatter/junit.rs b/apps/oxlint/src/output_formatter/junit.rs index 9e1faebcd5805..fe64e7158383d 100644 --- a/apps/oxlint/src/output_formatter/junit.rs +++ b/apps/oxlint/src/output_formatter/junit.rs @@ -117,6 +117,6 @@ mod test { reporter.render_error(warning); let output = reporter.finish(&DiagnosticResult::default()).unwrap(); - assert_eq!(output.to_string(), EXPECTED_REPORT); + assert_eq!(output, EXPECTED_REPORT); } } diff --git a/crates/oxc_linter/src/config/categories.rs b/crates/oxc_linter/src/config/categories.rs index 111a188f4c0b2..8787e8b69a83c 100644 --- a/crates/oxc_linter/src/config/categories.rs +++ b/crates/oxc_linter/src/config/categories.rs @@ -48,7 +48,7 @@ impl JsonSchema for OxlintCategories { properties.insert(RuleCategory::Perf.as_str().to_string(), severity.clone()); properties.insert(RuleCategory::Style.as_str().to_string(), severity.clone()); properties.insert(RuleCategory::Restriction.as_str().to_string(), severity.clone()); - properties.insert(RuleCategory::Nursery.as_str().to_string(), severity.clone()); + properties.insert(RuleCategory::Nursery.as_str().to_string(), severity); } { diff --git a/crates/oxc_linter/src/rules/eslint/func_names.rs b/crates/oxc_linter/src/rules/eslint/func_names.rs index 7ff69515855da..4dc46f9022912 100644 --- a/crates/oxc_linter/src/rules/eslint/func_names.rs +++ b/crates/oxc_linter/src/rules/eslint/func_names.rs @@ -676,7 +676,7 @@ fn test() { ("class C { public foo = function() {} }", always.clone()), // { "ecmaVersion": 2022 }, ("class C { [foo] = function() {} }", always.clone()), // { "ecmaVersion": 2022 }, ("class C { #foo = function() {} }", always.clone()), // { "ecmaVersion": 2022 }, - ("class C { foo = bar(function() {}) }", as_needed.clone()), // { "ecmaVersion": 2022 }, + ("class C { foo = bar(function() {}) }", as_needed), // { "ecmaVersion": 2022 }, ("class C { foo = function bar() {} }", never.clone()), // { "ecmaVersion": 2022 } ]; @@ -751,7 +751,7 @@ fn test() { "Foo.prototype.bar = function () {}", never.clone(), ), - ("class C { foo = function foo() {} }", "class C { foo = function () {} }", never.clone()), + ("class C { foo = function foo() {} }", "class C { foo = function () {} }", never), ( "const restoreGracefully = function (entries: T[]) { }", "const restoreGracefully = function restoreGracefully(entries: T[]) { }", @@ -794,7 +794,7 @@ fn test() { Component.prototype.setState = function (update, callback) { return setState.call(this, update, callback); };", - always.clone(), + always, ), ]; diff --git a/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs b/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs index 4a98150b9d127..1c9190dfea219 100644 --- a/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs +++ b/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs @@ -394,13 +394,13 @@ impl NoFallthrough { if let Some(end) = end { let range = start..end; - if is_fallthrough_comment_in_range(range.clone()) { + if is_fallthrough_comment_in_range(range) { return Some(Span::new(start, end)); } } let range = start..fall.span.start; - if is_fallthrough_comment_in_range(range.clone()) { + if is_fallthrough_comment_in_range(range) { Some(Span::new(start, fall.span.start)) } else { None diff --git a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs index 552ac4660799a..6a26c182bc7ec 100644 --- a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs +++ b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs @@ -572,7 +572,7 @@ fn test() { ("const func = (param = 123) => {}", ignore_default_values.clone()), // { "ecmaVersion": 6 }, ("const func = ({ param = 123 }) => {}", ignore_default_values.clone()), // { "ecmaVersion": 6 }, ("const [one = 1, two = 2] = []", ignore_default_values.clone()), // { "ecmaVersion": 6 }, - ("var one, two; [one = 1, two = 2] = []", ignore_default_values.clone()), // { "ecmaVersion": 6 }, + ("var one, two; [one = 1, two = 2] = []", ignore_default_values), // { "ecmaVersion": 6 }, ("var x = parseInt?.(y, 10);", None), // { "ecmaVersion": 2020 }, ("var x = Number?.parseInt(y, 10);", None), // { "ecmaVersion": 2020 }, ("var x = (Number?.parseInt)(y, 10);", None), // { "ecmaVersion": 2020 }, @@ -588,7 +588,7 @@ fn test() { ("type Foo = 1;", ignore_numeric_literal_types.clone()), ("type Foo = -1;", ignore_numeric_literal_types.clone()), ("type Foo = 1 | 2 | 3;", ignore_numeric_literal_types.clone()), - ("type Foo = 1 | -1;", ignore_numeric_literal_types.clone()), + ("type Foo = 1 | -1;", ignore_numeric_literal_types), ( " enum foo { @@ -624,7 +624,7 @@ fn test() { ("type Foo = Bar[1 & number];", ignore_typed_index_arrays.clone()), ("type Foo = Bar[((1 & -2) | 3) | 4];", ignore_typed_index_arrays.clone()), ("type Foo = Parameters[2];", ignore_typed_index_arrays.clone()), - ("type Foo = Bar['baz'];", ignore_typed_index_arrays.clone()), + ("type Foo = Bar['baz'];", ignore_typed_index_arrays), ("type Foo = Bar['baz'];", Some(serde_json::json!([{ "ignoreTypeIndexes": false }]))), ( " @@ -709,8 +709,8 @@ fn test() { let fail = vec![ ("var foo = 42", enforce_const.clone()), // { "ecmaVersion": 6 }, ("var foo = 0 + 1;", None), - ("var foo = 42n", enforce_const.clone()), // { "ecmaVersion": 2020 }, - ("var foo = 0n + 1n;", None), // { "ecmaVersion": 2020 }, + ("var foo = 42n", enforce_const), // { "ecmaVersion": 2020 }, + ("var foo = 0n + 1n;", None), // { "ecmaVersion": 2020 }, ("a = a + 5;", None), ("a += 5;", None), ("var foo = 0 + 1 + -2 + 2;", None), @@ -766,7 +766,7 @@ fn test() { // ("foo[+1n]", ignore_array_indexes.clone()), // { "ecmaVersion": 2020 }, // ("foo[- -1n]", ignore_array_indexes.clone()), // { "ecmaVersion": 2020 }, ("100 .toString()", ignore_array_indexes.clone()), - ("200[100]", ignore_array_indexes.clone()), + ("200[100]", ignore_array_indexes), ("var a =
;", None), // { "parserOptions": { "ecmaFeatures": { "jsx": true } } }, ("var min, max, mean; min = 1; max = 10; mean = 4;", Some(serde_json::json!([{}]))), ("f(100n)", Some(serde_json::json!([{ "ignore": [100] }]))), // { "ecmaVersion": 2020 }, @@ -815,7 +815,7 @@ fn test() { ), // { "ecmaVersion": 2022 }, ("class C { foo = 2 + 3; }", ignore_class_field_initial_values.clone()), // { "ecmaVersion": 2022 }, ("class C { 2; }", ignore_class_field_initial_values.clone()), // { "ecmaVersion": 2022 }, - ("class C { [2]; }", ignore_class_field_initial_values.clone()), // { "ecmaVersion": 2022 } + ("class C { [2]; }", ignore_class_field_initial_values), // { "ecmaVersion": 2022 } ("type Foo = 1;", Some(serde_json::json!([{ "ignoreNumericLiteralTypes": false }]))), ("type Foo = -1;", Some(serde_json::json!([{ "ignoreNumericLiteralTypes": false }]))), ( diff --git a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs index 1603bfaf6fd90..32c3a50415109 100644 --- a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs @@ -1012,11 +1012,11 @@ fn test() { ), ( r#"import { AllowedObject } from "foo";"#, - Some(serde_json::json!(pass_disallowed_object_foo.clone())), + Some(serde_json::json!(pass_disallowed_object_foo)), ), ( r#"import { 'AllowedObject' as bar } from "foo";"#, - Some(serde_json::json!(pass_disallowed_object_foo.clone())), + Some(serde_json::json!(pass_disallowed_object_foo)), ), ( r#"import { ' ' as bar } from "foo";"#, @@ -1058,7 +1058,7 @@ fn test() { ), ( r#"import AllowedObject, { AllowedObjectTwo as DisallowedObject } from "foo";"#, - Some(pass_disallowed_object_foo.clone()), + Some(pass_disallowed_object_foo), ), ( r#"import AllowedObject, { AllowedObjectTwo as DisallowedObject } from "foo";"#, diff --git a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs index 2a7c8f9edb6e3..3554982e63e5c 100644 --- a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs +++ b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs @@ -44,7 +44,7 @@ fn shadowed() { .unwrap(); test_same("(function (undefined) { let x = typeof undefined })()", config.clone()); test_same("(function (NaN) { let x = typeof NaN })()", config.clone()); - test_same("(function (process) { let x = process.env.NODE_ENV })()", config.clone()); + test_same("(function (process) { let x = process.env.NODE_ENV })()", config); } #[test] @@ -57,7 +57,7 @@ fn dot() { test("process", "process", config.clone()); // computed member expression - test("process['env'].NODE_ENV", "production", config.clone()); + test("process['env'].NODE_ENV", "production", config); } #[test] @@ -73,7 +73,7 @@ fn dot_with_overlap() { test("import.meta.env = 0", "__foo__ = 0", config.clone()); test("import.meta.env.NODE_ENV = 0", "__foo__.NODE_ENV = 0", config.clone()); - test("import.meta.env.FOO = 0", "import.meta.env.FOO = 0", config.clone()); + test("import.meta.env.FOO = 0", "import.meta.env.FOO = 0", config); } #[test] @@ -86,7 +86,7 @@ fn dot_define_is_member_expr_postfix() { test( "console.log(__OBJ__.process.env.SOMEVAR)", "console.log({ 'process': { 'env': { 'SOMEVAR': 'foo' } } }.process.env.SOMEVAR);\n", - config.clone(), + config, ); } @@ -133,7 +133,7 @@ fn optional_chain() { test_same("a[b][c]", config.clone()); test_same("a?.[b][c]", config.clone()); - test_same("a[b]?.[c]", config.clone()); + test_same("a[b]?.[c]", config); } #[test] @@ -152,7 +152,7 @@ fn dot_define_with_destruct() { test( "const {[any]: alias} = process.env.NODE_ENV", "const { [any]: alias } = {\n\t'a': 1,\n\tb: 2,\n\tc: true,\n\td: { a: b }\n};", - config.clone(), + config, ); // should filterout unused key even rhs objectExpr has SpreadElement @@ -165,7 +165,7 @@ fn dot_define_with_destruct() { test( "const {a} = process.env.NODE_ENV", "const { a } = {\n\t'a': 1,\n\t...unknown\n};\n", - config.clone(), + config, ); } @@ -233,7 +233,7 @@ console.log( ) ", "console.log([a = 0,b.c = 0,b['c'] = 0], [ident = 0,ident = 0,ident = 0], [dot.chain = 0,dot.chain = 0,dot.chain = 0\n]);", - config.clone(), + config, ); } diff --git a/tasks/ast_tools/src/generators/assert_layouts.rs b/tasks/ast_tools/src/generators/assert_layouts.rs index b1f7b2c56ea12..758152fdf2565 100644 --- a/tasks/ast_tools/src/generators/assert_layouts.rs +++ b/tasks/ast_tools/src/generators/assert_layouts.rs @@ -370,7 +370,7 @@ fn calculate_layout_for_primitive(primitive_def: &PrimitiveDef) -> Layout { "u128" => { panic!("Cannot calculate alignment for `u128`. It differs depending on Rust version.") } - "usize" => usize_layout.clone(), + "usize" => usize_layout, "i8" => Layout::from_type::(), "i16" => Layout::from_type::(), "i32" => Layout::from_type::(), @@ -378,10 +378,10 @@ fn calculate_layout_for_primitive(primitive_def: &PrimitiveDef) -> Layout { "i128" => { panic!("Cannot calculate alignment for `i128`. It differs depending on Rust version.") } - "isize" => usize_layout.clone(), + "isize" => usize_layout, "f32" => Layout::from_type::(), "f64" => Layout::from_type::(), - "&str" => str_layout.clone(), + "&str" => str_layout, "Atom" => str_layout, "NonZeroU8" => Layout::from_type_with_niche_for_zero::(), "NonZeroU16" => Layout::from_type_with_niche_for_zero::(), @@ -390,7 +390,7 @@ fn calculate_layout_for_primitive(primitive_def: &PrimitiveDef) -> Layout { "NonZeroU128" => { panic!("Cannot calculate alignment for `NonZeroU128`. It differs depending on Rust version.") } - "NonZeroUsize" => non_zero_usize_layout.clone(), + "NonZeroUsize" => non_zero_usize_layout, "NonZeroI8" => Layout::from_type_with_niche_for_zero::(), "NonZeroI16" => Layout::from_type_with_niche_for_zero::(), "NonZeroI32" => Layout::from_type_with_niche_for_zero::(), diff --git a/tasks/coverage/src/misc/mod.rs b/tasks/coverage/src/misc/mod.rs index ab1d5f0e93316..fb6209cde94fc 100644 --- a/tasks/coverage/src/misc/mod.rs +++ b/tasks/coverage/src/misc/mod.rs @@ -22,13 +22,13 @@ impl MiscSuite { fn huge_binary_expression() -> T { let code = String::from("a") + &"+ a".repeat(1000); - T::new(PathBuf::from("huge_binary_expression.js"), code.to_string()) + T::new(PathBuf::from("huge_binary_expression.js"), code) } fn huge_nested_statements() -> T { let take = 1000; let code = "if (true) {".repeat(take) + &"}".repeat(take); - T::new(PathBuf::from("huge_nested_statements.js"), code.to_string()) + T::new(PathBuf::from("huge_nested_statements.js"), code) } } diff --git a/tasks/prettier_conformance/src/main.rs b/tasks/prettier_conformance/src/main.rs index 099e46ff90306..ca62a81a2a02b 100644 --- a/tasks/prettier_conformance/src/main.rs +++ b/tasks/prettier_conformance/src/main.rs @@ -13,5 +13,5 @@ fn main() { let filter = args.opt_value_from_str("--filter").unwrap(); TestRunner::new(TestRunnerOptions { filter: filter.clone(), language: TestLanguage::Js }).run(); - TestRunner::new(TestRunnerOptions { filter: filter.clone(), language: TestLanguage::Ts }).run(); + TestRunner::new(TestRunnerOptions { filter, language: TestLanguage::Ts }).run(); } diff --git a/tasks/rulegen/src/main.rs b/tasks/rulegen/src/main.rs index e84cf749f549c..5ebd9351b69c6 100644 --- a/tasks/rulegen/src/main.rs +++ b/tasks/rulegen/src/main.rs @@ -177,7 +177,7 @@ fn format_tagged_template_expression(tag_expr: &TaggedTemplateExpression) -> Opt if tag_expr.tag.is_specific_member_access("String", "raw") { tag_expr.quasi.quasis.first().map(|quasi| format!("r#\"{}\"#", quasi.value.raw)) } else if tag_expr.tag.is_specific_id("dedent") || tag_expr.tag.is_specific_id("outdent") { - tag_expr.quasi.quasis.first().map(|quasi| util::dedent(&quasi.value.raw).to_string()) + tag_expr.quasi.quasis.first().map(|quasi| util::dedent(&quasi.value.raw)) } else { tag_expr.quasi.quasi().map(|quasi| quasi.to_string()) } diff --git a/tasks/transform_conformance/src/main.rs b/tasks/transform_conformance/src/main.rs index 9ba53f65fca4e..3e7fa1da72eb4 100644 --- a/tasks/transform_conformance/src/main.rs +++ b/tasks/transform_conformance/src/main.rs @@ -19,5 +19,5 @@ fn main() { ); } - TestRunner::new(options.clone()).run(); + TestRunner::new(options).run(); } diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 9967118e59bb1..06aad91f5edfc 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -245,7 +245,7 @@ impl TestCase { if !errors.is_empty() { let source = NamedSource::new( path.strip_prefix(project_root).unwrap().to_string_lossy(), - source_text.to_string(), + source_text, ); return Err(errors .into_iter()