From d15c856b13b18935eb76c889a8eea65682b89719 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 10 Jan 2025 06:41:53 +0000 Subject: [PATCH] chore(rust): update clippy rules (#8408) --- Cargo.toml | 5 ++-- apps/oxlint/src/lint.rs | 18 +++---------- .../peephole_substitute_alternate_syntax.rs | 25 ++++++++++++------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dddbe7f6125af..7c07bc8ccd931 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,13 +48,14 @@ rest_pat_in_fully_bound_structs = "warn" unnecessary_safety_comment = "warn" undocumented_unsafe_blocks = "warn" infinite_loop = "warn" +map_with_unused_argument_over_ranges = "warn" +unused_result_ok = "warn" +pathbuf_init_then_push = "warn" # I want to write the best Rust code so pedantic is enabled. # We should only disable rules globally if they are either false positives, chaotic, or does not make sense. pedantic = { level = "warn", priority = -1 } # Allowed rules # pedantic -# This rule is too pedantic, I don't want to force this because naming things are hard. -module_name_repetitions = "allow" # All triggers are mostly ignored in our codebase, so this is ignored globally. struct_excessive_bools = "allow" too_many_lines = "allow" diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 8ea5c15f7bbc6..d2b03b79d2494 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -74,14 +74,7 @@ impl Runner for LintRunner { } // Append cwd to all paths - paths = paths - .into_iter() - .map(|x| { - let mut path_with_cwd = self.cwd.clone(); - path_with_cwd.push(x); - path_with_cwd - }) - .collect(); + paths = paths.into_iter().map(|x| self.cwd.join(x)).collect(); if paths.is_empty() { // If explicit paths were provided, but all have been @@ -268,9 +261,7 @@ impl LintRunner { // when no file is found, the default configuration is returned fn find_oxlint_config(cwd: &Path, config: Option<&PathBuf>) -> Result { if let Some(config_path) = config { - let mut full_path = cwd.to_path_buf(); - full_path.push(config_path); - + let full_path = cwd.join(config_path); return match Oxlintrc::from_file(&full_path) { Ok(config) => Ok(config), Err(diagnostic) => { @@ -283,13 +274,10 @@ impl LintRunner { } }; } - // no config argument is provided, // auto detect default config file from current work directory // or return the default configuration, when no valid file is found - let mut config_path = cwd.to_path_buf(); - config_path.push(Self::DEFAULT_OXLINTRC); - + let config_path = cwd.join(Self::DEFAULT_OXLINTRC); Oxlintrc::from_file(&config_path).or_else(|_| Ok(Oxlintrc::default())) } } diff --git a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index 2048f8e828f43..9543cc924598c 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -889,17 +889,24 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax { // new Array(2) -> `[,,]` // this does not work with IE8 and below // learned from https://github.com/babel/minify/pull/45 - #[expect(clippy::cast_possible_truncation)] + #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)] if n.value.fract() == 0.0 { - let n_int = n.value as i64; + let n_int = n.value as usize; if (1..=6).contains(&n_int) { - return Some(ctx.ast.expression_array( - span, - ctx.ast.vec_from_iter((0..n_int).map(|_| { - ArrayExpressionElement::Elision(Elision { span: SPAN }) - })), - None, - )); + return Some( + ctx.ast.expression_array( + span, + ctx.ast.vec_from_iter( + std::iter::from_fn(|| { + Some(ArrayExpressionElement::Elision( + ctx.ast.elision(SPAN), + )) + }) + .take(n_int), + ), + None, + ), + ); } }