diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..434e968 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.51.0" diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml index ccb2820..56757a8 100644 --- a/.github/workflows/style.yaml +++ b/.github/workflows/style.yaml @@ -14,3 +14,12 @@ jobs: - run: rustup component add rustfmt - name: Check formatting run: cargo fmt --all -- --check + # Check for code issues + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: rustup update stable && rustup default stable + - run: rustup component add clippy + - name: Run linter + run: cargo clippy --color=always -- -D warnings diff --git a/src/main.rs b/src/main.rs index 6ffebe7..57556e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,11 +64,7 @@ fn display_generic_error(error: &valgrind::xml::Error) { eprintln!( "{:>12} {}", "Error".red().bold(), - error - .main_info - .as_ref() - .map(String::as_str) - .unwrap_or("unknown"), + error.main_info.as_ref().map_or("unknown", String::as_str) ); let stack = &error.stack_trace[0]; // always available @@ -83,10 +79,11 @@ fn display_generic_error(error: &valgrind::xml::Error) { display_stack_trace( msg.map_or_else(|| "additional stack trace", String::as_str), stack, - ) - }) + ); + }); } +/// Write out the full stack trace (indented to match other messages). fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) { eprintln!("{:>12} {}", "Info".cyan().bold(), msg); stack @@ -98,7 +95,7 @@ fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) { fn main() { panic::replace_hook(); - let number_of_arguments = || env::args_os().skip(0).count(); + let number_of_arguments = || env::args_os().skip(1).count(); let help_requested = || env::args_os().any(|arg| arg == "--help" || arg == "-h"); let is_cargo_subcommand = || env::args_os().nth(1).map_or(false, |arg| arg == "valgrind"); if number_of_arguments() == 0 || help_requested() { diff --git a/src/panic.rs b/src/panic.rs index c83abb8..d14e510 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -32,6 +32,7 @@ const PANIC_HEADER: &str = " /// /// This is helpful for printing debug information to the panic message. #[macro_export] +#[allow(clippy::module_name_repetitions)] // necessary for exported macro macro_rules! panic_with { ($e:expr) => { std::panic::panic_any($e) diff --git a/src/valgrind/mod.rs b/src/valgrind/mod.rs index c4c3612..45ceb15 100644 --- a/src/valgrind/mod.rs +++ b/src/valgrind/mod.rs @@ -60,7 +60,7 @@ where // additional options to pass to valgrind? if let Ok(additional_args) = env::var("VALGRINDFLAGS") { - valgrind.args(additional_args.split(" ")); + valgrind.args(additional_args.split(' ')); } let cargo = valgrind diff --git a/src/valgrind/xml/mod.rs b/src/valgrind/xml/mod.rs index 165e1fa..204673e 100644 --- a/src/valgrind/xml/mod.rs +++ b/src/valgrind/xml/mod.rs @@ -92,23 +92,23 @@ pub enum Kind { } impl Kind { /// Query, if the current error kind is a memory leak - pub(crate) fn is_leak(&self) -> bool { + pub(crate) const fn is_leak(self) -> bool { match self { - Kind::LeakDefinitelyLost - | Kind::LeakStillReachable - | Kind::LeakIndirectlyLost - | Kind::LeakPossiblyLost => true, - Kind::InvalidFree - | Kind::MismatchedFree - | Kind::InvalidRead - | Kind::InvalidWrite - | Kind::InvalidJump - | Kind::Overlap - | Kind::InvalidMemPool - | Kind::UninitCondition - | Kind::UninitValue - | Kind::SyscallParam - | Kind::ClientCheck => false, + Self::LeakDefinitelyLost + | Self::LeakStillReachable + | Self::LeakIndirectlyLost + | Self::LeakPossiblyLost => true, + Self::InvalidFree + | Self::MismatchedFree + | Self::InvalidRead + | Self::InvalidWrite + | Self::InvalidJump + | Self::Overlap + | Self::InvalidMemPool + | Self::UninitCondition + | Self::UninitValue + | Self::SyscallParam + | Self::ClientCheck => false, } } }