From 37edbcfebc4e8f43d5483a0e47385308fc90bb42 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 13 Nov 2022 15:31:19 -0800 Subject: [PATCH] refactor(clippy): apply various lint fixes --- komorebi-core/src/config_generation.rs | 4 +-- komorebi-core/src/direction.rs | 34 +++++++++----------- komorebi/src/main.rs | 6 ++-- komorebi/src/monitor.rs | 1 + komorebi/src/process_command.rs | 8 ++--- komorebic/src/main.rs | 43 +++++++++++++------------- 6 files changed, 45 insertions(+), 51 deletions(-) diff --git a/komorebi-core/src/config_generation.rs b/komorebi-core/src/config_generation.rs index 6ca16731..eab22060 100644 --- a/komorebi-core/src/config_generation.rs +++ b/komorebi-core/src/config_generation.rs @@ -131,7 +131,7 @@ impl ApplicationConfigurationGenerator { String::from("; Generated by komorebic.exe"), String::from("; To use this file, add the line below to the top of your komorebi.ahk configuration file"), String::from("; #Include %A_ScriptDir%\\komorebi.generated.ahk"), - String::from("") + String::new() ]; let mut float_rules = vec![]; @@ -168,7 +168,7 @@ impl ApplicationConfigurationGenerator { } } - lines.push(String::from("")); + lines.push(String::new()); } Ok(lines) diff --git a/komorebi-core/src/direction.rs b/komorebi-core/src/direction.rs index 225ca426..bfad73f0 100644 --- a/komorebi-core/src/direction.rs +++ b/komorebi-core/src/direction.rs @@ -229,16 +229,13 @@ impl Direction for CustomLayout { } let (column_idx, column) = self.column_with_idx(idx); - match column { - None => false, - Some(column) => match column { - Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) - | Column::Tertiary(ColumnSplit::Horizontal) => { - self.column_for_container_idx(idx - 1) == column_idx - } - _ => false, - }, - } + column.map_or(false, |column| match column { + Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) + | Column::Tertiary(ColumnSplit::Horizontal) => { + self.column_for_container_idx(idx - 1) == column_idx + } + _ => false, + }) } OperationDirection::Down => { if idx == count - 1 { @@ -246,16 +243,13 @@ impl Direction for CustomLayout { } let (column_idx, column) = self.column_with_idx(idx); - match column { - None => false, - Some(column) => match column { - Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) - | Column::Tertiary(ColumnSplit::Horizontal) => { - self.column_for_container_idx(idx + 1) == column_idx - } - _ => false, - }, - } + column.map_or(false, |column| match column { + Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) + | Column::Tertiary(ColumnSplit::Horizontal) => { + self.column_for_container_idx(idx + 1) == column_idx + } + _ => false, + }) } } } diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index d8b2ace4..37f67be8 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -113,7 +113,7 @@ lazy_static! { static ref HIDING_BEHAVIOUR: Arc> = Arc::new(Mutex::new(HidingBehaviour::Minimize)); static ref HOME_DIR: PathBuf = { - if let Ok(home_path) = std::env::var("KOMOREBI_CONFIG_HOME") { + std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(|_| dirs::home_dir().expect("there is no home directory"), |home_path| { let home = PathBuf::from(&home_path); if home.as_path().is_dir() { @@ -124,9 +124,7 @@ lazy_static! { home_path ); } - } else { - dirs::home_dir().expect("there is no home directory") - } + }) }; static ref DATA_DIR: PathBuf = dirs::data_local_dir().expect("there is no local data directory").join("komorebi"); static ref AHK_V1_EXE: String = { diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 2d525215..da26bb81 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -127,6 +127,7 @@ impl Monitor { let workspaces = self.workspaces_mut(); + #[allow(clippy::option_if_let_else)] let target_workspace = match workspaces.get_mut(target_workspace_idx) { None => { workspaces.resize(target_workspace_idx + 1, Workspace::default()); diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index b2cef345..23ecb541 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -435,7 +435,7 @@ impl WindowManager { socket.push("komorebic.sock"); let socket = socket.as_path(); - let mut stream = UnixStream::connect(&socket)?; + let mut stream = UnixStream::connect(socket)?; stream.write_all(state.as_bytes())?; } SocketMessage::Query(query) => { @@ -458,7 +458,7 @@ impl WindowManager { socket.push("komorebic.sock"); let socket = socket.as_path(); - let mut stream = UnixStream::connect(&socket)?; + let mut stream = UnixStream::connect(socket)?; stream.write_all(response.as_bytes())?; } SocketMessage::ResizeWindowEdge(direction, sizing) => { @@ -856,7 +856,7 @@ impl WindowManager { socket.push("komorebic.sock"); let socket = socket.as_path(); - let mut stream = UnixStream::connect(&socket)?; + let mut stream = UnixStream::connect(socket)?; stream.write_all(schema.as_bytes())?; } SocketMessage::SocketSchema => { @@ -866,7 +866,7 @@ impl WindowManager { socket.push("komorebic.sock"); let socket = socket.as_path(); - let mut stream = UnixStream::connect(&socket)?; + let mut stream = UnixStream::connect(socket)?; stream.write_all(schema.as_bytes())?; } }; diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 47735d2f..4f7cdda2 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -48,20 +48,21 @@ use komorebi_core::WindowKind; lazy_static! { static ref HOME_DIR: PathBuf = { - if let Ok(home_path) = std::env::var("KOMOREBI_CONFIG_HOME") { - let home = PathBuf::from(&home_path); + std::env::var("KOMOREBI_CONFIG_HOME").map_or_else( + |_| dirs::home_dir().expect("there is no home directory"), + |home_path| { + let home = PathBuf::from(&home_path); - if home.as_path().is_dir() { - home - } else { - panic!( - "$Env:KOMOREBI_CONFIG_HOME is set to '{}', which is not a valid directory", - home_path - ); - } - } else { - dirs::home_dir().expect("there is no home directory") - } + if home.as_path().is_dir() { + home + } else { + panic!( + "$Env:KOMOREBI_CONFIG_HOME is set to '{}', which is not a valid directory", + home_path + ); + } + }, + ) }; static ref DATA_DIR: PathBuf = dirs::data_local_dir() .expect("there is no local data directory") @@ -1181,7 +1182,7 @@ fn main() -> Result<()> { socket.push("komorebic.sock"); let socket = socket.as_path(); - match std::fs::remove_file(&socket) { + match std::fs::remove_file(socket) { Ok(_) => {} Err(error) => match error.kind() { // Doing this because ::exists() doesn't work reliably on Windows via IntelliJ @@ -1192,7 +1193,7 @@ fn main() -> Result<()> { }, }; - let listener = UnixListener::bind(&socket)?; + let listener = UnixListener::bind(socket)?; send_message(&SocketMessage::State.as_bytes()?)?; @@ -1216,7 +1217,7 @@ fn main() -> Result<()> { socket.push("komorebic.sock"); let socket = socket.as_path(); - match std::fs::remove_file(&socket) { + match std::fs::remove_file(socket) { Ok(_) => {} Err(error) => match error.kind() { // Doing this because ::exists() doesn't work reliably on Windows via IntelliJ @@ -1227,7 +1228,7 @@ fn main() -> Result<()> { }, }; - let listener = UnixListener::bind(&socket)?; + let listener = UnixListener::bind(socket)?; send_message(&SocketMessage::Query(arg.state_query).as_bytes()?)?; @@ -1419,7 +1420,7 @@ fn main() -> Result<()> { socket.push("komorebic.sock"); let socket = socket.as_path(); - match std::fs::remove_file(&socket) { + match std::fs::remove_file(socket) { Ok(_) => {} Err(error) => match error.kind() { // Doing this because ::exists() doesn't work reliably on Windows via IntelliJ @@ -1432,7 +1433,7 @@ fn main() -> Result<()> { send_message(&SocketMessage::NotificationSchema.as_bytes()?)?; - let listener = UnixListener::bind(&socket)?; + let listener = UnixListener::bind(socket)?; match listener.accept() { Ok(incoming) => { let stream = BufReader::new(incoming.0); @@ -1453,7 +1454,7 @@ fn main() -> Result<()> { socket.push("komorebic.sock"); let socket = socket.as_path(); - match std::fs::remove_file(&socket) { + match std::fs::remove_file(socket) { Ok(_) => {} Err(error) => match error.kind() { // Doing this because ::exists() doesn't work reliably on Windows via IntelliJ @@ -1466,7 +1467,7 @@ fn main() -> Result<()> { send_message(&SocketMessage::SocketSchema.as_bytes()?)?; - let listener = UnixListener::bind(&socket)?; + let listener = UnixListener::bind(socket)?; match listener.accept() { Ok(incoming) => { let stream = BufReader::new(incoming.0);