Skip to content

Commit

Permalink
chore(rust): update clippy rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 10, 2025
1 parent 4743225 commit 883fe8f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 3 additions & 15 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Oxlintrc, CliRunResult> {
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) => {
Expand All @@ -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()))
}
}
Expand Down
6 changes: 0 additions & 6 deletions crates/oxc_data_structures/src/stack/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ use std::{cmp::Ordering, ptr::NonNull as NativeNonNull};
#[repr(transparent)]
pub struct NonNull<T>(NativeNonNull<T>);

#[cfg(clippy)]
#[expect(clippy::incompatible_msrv)]
unsafe fn _non_null_add_is_not_stable(ptr: NativeNonNull<u8>) -> NativeNonNull<u8> {
ptr.add(1)
}

impl<T> NonNull<T> {
#[inline(always)]
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
}

Expand Down

0 comments on commit 883fe8f

Please sign in to comment.