diff --git a/maa-cli/src/cleanup.rs b/maa-cli/src/cleanup.rs index c01677e2..d00b9fb3 100644 --- a/maa-cli/src/cleanup.rs +++ b/maa-cli/src/cleanup.rs @@ -22,7 +22,10 @@ pub trait PathProvider { /// deleted. This method and `should_keep` determine whether an entry should be deleted. /// If this method returns true and `should_keep` returns false, the entry will be deleted. /// Otherwise, the entry will not be deleted. - #[allow(unused_variables)] + #[expect( + unused_variables, + reason = "This is default implementation, the variable may used by other implementations" + )] fn should_delete(&self, entry: &DirEntry) -> bool { true } @@ -33,7 +36,10 @@ pub trait PathProvider { /// This method and `should_delete` determine whether an entry should be deleted. /// If `should_delete` returns true and this method returns false, the entry will be deleted. /// Otherwise, the entry will not be deleted. - #[allow(unused_variables)] + #[expect( + unused_variables, + reason = "This is default implementation, the variable may used by other implementations" + )] fn should_keep(&self, entry: &DirEntry) -> bool { false } diff --git a/maa-cli/src/command.rs b/maa-cli/src/command.rs index a0b19fa8..07953a0d 100644 --- a/maa-cli/src/command.rs +++ b/maa-cli/src/command.rs @@ -7,8 +7,7 @@ use crate::{cleanup, config, log, run}; #[derive(Parser)] #[command(name = "maa", author, version = env!("MAA_VERSION"), about = "A tool for Arknights.")] -#[allow(clippy::upper_case_acronyms)] -pub(crate) struct CLI { +pub(crate) struct Cli { #[command(subcommand)] pub(crate) command: Command, /// Enable batch mode @@ -300,12 +299,12 @@ pub(crate) enum Dir { } #[cfg(test)] -pub(crate) fn parse_from(args: I) -> CLI +pub(crate) fn parse_from(args: I) -> Cli where I: IntoIterator, T: Into + Clone, { - CLI::parse_from(args) + Cli::parse_from(args) } #[cfg(test)] diff --git a/maa-cli/src/config/asst.rs b/maa-cli/src/config/asst.rs index d4a9b1b7..3b011daa 100644 --- a/maa-cli/src/config/asst.rs +++ b/maa-cli/src/config/asst.rs @@ -119,12 +119,11 @@ impl ConnectionConfig { #[cfg_attr(test, derive(Debug, PartialEq))] #[derive(Default, Clone, Copy)] -#[allow(clippy::upper_case_acronyms)] pub enum Preset { MuMuPro, PlayCover, #[default] - ADB, + Adb, } impl<'de> Deserialize<'de> for Preset { @@ -148,10 +147,10 @@ impl<'de> Deserialize<'de> for Preset { match value { "MuMuPro" => Ok(Preset::MuMuPro), "PlayCover" | "PlayTools" => Ok(Preset::PlayCover), - "ADB" => Ok(Preset::ADB), + "ADB" | "Adb" | "adb" => Ok(Preset::Adb), _ => { warn!("Unknown connection preset: {}, ignoring", value); - Ok(Preset::ADB) + Ok(Preset::Adb) } } } @@ -166,7 +165,7 @@ impl Preset { match self { Preset::MuMuPro => "/Applications/MuMuPlayer.app/Contents/MacOS/MuMuEmulator.app/Contents/MacOS/tools/adb", Preset::PlayCover => "", - Preset::ADB => "adb", + Preset::Adb => "adb", } } @@ -174,7 +173,7 @@ impl Preset { match self { Preset::MuMuPro => "127.0.0.1:16384".into(), Preset::PlayCover => "127.0.0.1:1717".into(), - Preset::ADB => std::process::Command::new(adb_path) + Preset::Adb => std::process::Command::new(adb_path) .arg("devices") .output() .ok() @@ -534,7 +533,7 @@ mod tests { assert_eq!(config, AsstConfig { connection: ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, adb_path: Some(String::from("adb")), address: Some(String::from("emulator-5554")), config: Some(String::from("CompatMac")), @@ -571,7 +570,7 @@ mod tests { assert_de_tokens( &ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, ..Default::default() }, &[ @@ -584,7 +583,7 @@ mod tests { assert_de_tokens( &ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, ..Default::default() }, &[ @@ -610,7 +609,7 @@ mod tests { assert_de_tokens( &ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, adb_path: Some(String::from("/path/to/adb")), address: Some(String::from("127.0.0.1:5555")), config: Some(String::from("SomeConfig")), @@ -743,6 +742,15 @@ mod tests { ); } + #[test] + fn preset() { + assert_de_tokens(&Preset::Adb, &[Token::Str("ADB")]); + assert_de_tokens(&Preset::Adb, &[Token::Str("Adb")]); + assert_de_tokens(&Preset::Adb, &[Token::Str("adb")]); + + assert_de_tokens(&Preset::MuMuPro, &[Token::Str("MuMuPro")]); + } + #[test] fn asst_config() { assert_de_tokens( @@ -804,7 +812,7 @@ mod tests { #[test] fn default() { assert_matches!(ConnectionConfig::default(), ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, adb_path: None, address: None, config: None, @@ -814,7 +822,7 @@ mod tests { #[cfg(target_os = "macos")] #[test] fn preset() { - assert_eq!(ConnectionConfig::default().preset(), Preset::ADB); + assert_eq!(ConnectionConfig::default().preset(), Preset::Adb); assert_eq!( ConnectionConfig { @@ -889,7 +897,7 @@ mod tests { args_eq( ConnectionConfig { - preset: Preset::ADB, + preset: Preset::Adb, adb_path: Some("/path/to/adb".to_owned()), address: Some("127.0.0.1:11111".to_owned()), config: Some("SomeConfig".to_owned()), diff --git a/maa-cli/src/main.rs b/maa-cli/src/main.rs index 53cc8801..2826fefa 100644 --- a/maa-cli/src/main.rs +++ b/maa-cli/src/main.rs @@ -15,10 +15,10 @@ mod value; use anyhow::{Context, Result}; use clap::{CommandFactory, Parser}; -use crate::command::{Command, Component, Dir, CLI}; +use crate::command::{Cli, Command, Component, Dir}; fn main() -> Result<()> { - let cli = command::CLI::parse(); + let cli = command::Cli::parse(); cli.log.init_logger()?; @@ -120,7 +120,7 @@ fn main() -> Result<()> { config_type, } => config::import(&path, force, &config_type)?, Command::Complete { shell } => { - clap_complete::generate(shell, &mut CLI::command(), "maa", &mut std::io::stdout()); + clap_complete::generate(shell, &mut Cli::command(), "maa", &mut std::io::stdout()); } Command::Init { name, @@ -128,7 +128,7 @@ fn main() -> Result<()> { force, } => config::init::init(name, format, force)?, Command::Mangen { path } => { - clap_mangen::generate_to(CLI::command(), path)?; + clap_mangen::generate_to(Cli::command(), path)?; } } diff --git a/maa-dirs/src/lib.rs b/maa-dirs/src/lib.rs index c91e7108..3d417462 100644 --- a/maa-dirs/src/lib.rs +++ b/maa-dirs/src/lib.rs @@ -16,7 +16,10 @@ use dunce::canonicalize; macro_rules! str_join { ($($e:expr),*) => {{ const LEN: usize = 0 $(+ $e.len())*; - #[allow(unused_assignments)] + #[expect( + unused_assignments, + reason = "The last assignment will not be used, but in macro, we can't avoid it." + )] const BYTES: [u8; LEN] = { let mut dest: [u8; LEN] = [0; LEN]; let mut offset = 0; @@ -467,9 +470,7 @@ where /// # Panics /// /// Panics if the given str is a string containing path separator. -/// -/// This function only called at compile time, so it's dead code in release build. -#[allow(dead_code)] +#[allow(dead_code, reason = "This function is only called at compile time")] fn ensure_name(name: &str) -> &str { assert!( !name.contains(std::path::is_separator), @@ -828,10 +829,9 @@ mod tests { std::fs::File::create(&test_file).unwrap(); - assert_eq!( - global_path([&test_dir1, &test_dir2], "test"), - vec![test_file.clone()] - ); + assert_eq!(global_path([&test_dir1, &test_dir2], "test"), vec![ + test_file.clone() + ]); assert_eq!( global_path([&test_dir1, &test_dir2], "not_exist"), Vec::::new() diff --git a/maa-sys/src/link.rs b/maa-sys/src/link.rs index f8075beb..c15fac8b 100644 --- a/maa-sys/src/link.rs +++ b/maa-sys/src/link.rs @@ -7,7 +7,7 @@ macro_rules! link { ) => ( use libloading::{Library, Symbol}; - #[allow(non_snake_case)] + #[expect(non_snake_case, reason = "FFI functions are named in PascalCase")] struct SharedLibrary { _handle: Library, $( @@ -33,7 +33,7 @@ macro_rules! link { } $( - #[allow(non_snake_case)] + #[allow(non_snake_case, reason = "FFI functions are named in PascalCase")] pub fn $name(&self, $($pname: $pty), *) $(-> $ret)* { (self.$name)($($pname), *) } @@ -73,7 +73,7 @@ macro_rules! link { /// # Panics /// /// This function will panic if the shared library is not loaded in this thread. - #[allow(non_snake_case)] + #[allow(non_snake_case, reason = "FFI functions are named in PascalCase")] pub unsafe fn $name($($pname: $pty), *) $(-> $ret)* { match SHARED_LIBRARY.read().expect("Failed to lock shared library").as_ref() { Some(lib) => lib.$name($($pname), *),