refactor(clippy): apply various lint fixes

This commit is contained in:
LGUG2Z
2022-11-13 15:31:19 -08:00
parent b010215318
commit 37edbcfebc
6 changed files with 45 additions and 51 deletions

View File

@@ -131,7 +131,7 @@ impl ApplicationConfigurationGenerator {
String::from("; Generated by komorebic.exe"), 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("; 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("; #Include %A_ScriptDir%\\komorebi.generated.ahk"),
String::from("") String::new()
]; ];
let mut float_rules = vec![]; let mut float_rules = vec![];
@@ -168,7 +168,7 @@ impl ApplicationConfigurationGenerator {
} }
} }
lines.push(String::from("")); lines.push(String::new());
} }
Ok(lines) Ok(lines)

View File

@@ -229,16 +229,13 @@ impl Direction for CustomLayout {
} }
let (column_idx, column) = self.column_with_idx(idx); let (column_idx, column) = self.column_with_idx(idx);
match column { column.map_or(false, |column| match column {
None => false, Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_)))
Some(column) => match column { | Column::Tertiary(ColumnSplit::Horizontal) => {
Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) self.column_for_container_idx(idx - 1) == column_idx
| Column::Tertiary(ColumnSplit::Horizontal) => { }
self.column_for_container_idx(idx - 1) == column_idx _ => false,
} })
_ => false,
},
}
} }
OperationDirection::Down => { OperationDirection::Down => {
if idx == count - 1 { if idx == count - 1 {
@@ -246,16 +243,13 @@ impl Direction for CustomLayout {
} }
let (column_idx, column) = self.column_with_idx(idx); let (column_idx, column) = self.column_with_idx(idx);
match column { column.map_or(false, |column| match column {
None => false, Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_)))
Some(column) => match column { | Column::Tertiary(ColumnSplit::Horizontal) => {
Column::Secondary(Some(ColumnSplitWithCapacity::Horizontal(_))) self.column_for_container_idx(idx + 1) == column_idx
| Column::Tertiary(ColumnSplit::Horizontal) => { }
self.column_for_container_idx(idx + 1) == column_idx _ => false,
} })
_ => false,
},
}
} }
} }
} }

View File

@@ -113,7 +113,7 @@ lazy_static! {
static ref HIDING_BEHAVIOUR: Arc<Mutex<HidingBehaviour>> = static ref HIDING_BEHAVIOUR: Arc<Mutex<HidingBehaviour>> =
Arc::new(Mutex::new(HidingBehaviour::Minimize)); Arc::new(Mutex::new(HidingBehaviour::Minimize));
static ref HOME_DIR: PathBuf = { 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); let home = PathBuf::from(&home_path);
if home.as_path().is_dir() { if home.as_path().is_dir() {
@@ -124,9 +124,7 @@ lazy_static! {
home_path 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 DATA_DIR: PathBuf = dirs::data_local_dir().expect("there is no local data directory").join("komorebi");
static ref AHK_V1_EXE: String = { static ref AHK_V1_EXE: String = {

View File

@@ -127,6 +127,7 @@ impl Monitor {
let workspaces = self.workspaces_mut(); let workspaces = self.workspaces_mut();
#[allow(clippy::option_if_let_else)]
let target_workspace = match workspaces.get_mut(target_workspace_idx) { let target_workspace = match workspaces.get_mut(target_workspace_idx) {
None => { None => {
workspaces.resize(target_workspace_idx + 1, Workspace::default()); workspaces.resize(target_workspace_idx + 1, Workspace::default());

View File

@@ -435,7 +435,7 @@ impl WindowManager {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
let mut stream = UnixStream::connect(&socket)?; let mut stream = UnixStream::connect(socket)?;
stream.write_all(state.as_bytes())?; stream.write_all(state.as_bytes())?;
} }
SocketMessage::Query(query) => { SocketMessage::Query(query) => {
@@ -458,7 +458,7 @@ impl WindowManager {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
let mut stream = UnixStream::connect(&socket)?; let mut stream = UnixStream::connect(socket)?;
stream.write_all(response.as_bytes())?; stream.write_all(response.as_bytes())?;
} }
SocketMessage::ResizeWindowEdge(direction, sizing) => { SocketMessage::ResizeWindowEdge(direction, sizing) => {
@@ -856,7 +856,7 @@ impl WindowManager {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
let mut stream = UnixStream::connect(&socket)?; let mut stream = UnixStream::connect(socket)?;
stream.write_all(schema.as_bytes())?; stream.write_all(schema.as_bytes())?;
} }
SocketMessage::SocketSchema => { SocketMessage::SocketSchema => {
@@ -866,7 +866,7 @@ impl WindowManager {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
let mut stream = UnixStream::connect(&socket)?; let mut stream = UnixStream::connect(socket)?;
stream.write_all(schema.as_bytes())?; stream.write_all(schema.as_bytes())?;
} }
}; };

View File

@@ -48,20 +48,21 @@ use komorebi_core::WindowKind;
lazy_static! { lazy_static! {
static ref HOME_DIR: PathBuf = { 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(
let home = PathBuf::from(&home_path); |_| dirs::home_dir().expect("there is no home directory"),
|home_path| {
let home = PathBuf::from(&home_path);
if home.as_path().is_dir() { if home.as_path().is_dir() {
home home
} else { } else {
panic!( panic!(
"$Env:KOMOREBI_CONFIG_HOME is set to '{}', which is not a valid directory", "$Env:KOMOREBI_CONFIG_HOME is set to '{}', which is not a valid directory",
home_path home_path
); );
} }
} else { },
dirs::home_dir().expect("there is no home directory") )
}
}; };
static ref DATA_DIR: PathBuf = dirs::data_local_dir() static ref DATA_DIR: PathBuf = dirs::data_local_dir()
.expect("there is no local data directory") .expect("there is no local data directory")
@@ -1181,7 +1182,7 @@ fn main() -> Result<()> {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
match std::fs::remove_file(&socket) { match std::fs::remove_file(socket) {
Ok(_) => {} Ok(_) => {}
Err(error) => match error.kind() { Err(error) => match error.kind() {
// Doing this because ::exists() doesn't work reliably on Windows via IntelliJ // 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()?)?; send_message(&SocketMessage::State.as_bytes()?)?;
@@ -1216,7 +1217,7 @@ fn main() -> Result<()> {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
match std::fs::remove_file(&socket) { match std::fs::remove_file(socket) {
Ok(_) => {} Ok(_) => {}
Err(error) => match error.kind() { Err(error) => match error.kind() {
// Doing this because ::exists() doesn't work reliably on Windows via IntelliJ // 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()?)?; send_message(&SocketMessage::Query(arg.state_query).as_bytes()?)?;
@@ -1419,7 +1420,7 @@ fn main() -> Result<()> {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
match std::fs::remove_file(&socket) { match std::fs::remove_file(socket) {
Ok(_) => {} Ok(_) => {}
Err(error) => match error.kind() { Err(error) => match error.kind() {
// Doing this because ::exists() doesn't work reliably on Windows via IntelliJ // 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()?)?; send_message(&SocketMessage::NotificationSchema.as_bytes()?)?;
let listener = UnixListener::bind(&socket)?; let listener = UnixListener::bind(socket)?;
match listener.accept() { match listener.accept() {
Ok(incoming) => { Ok(incoming) => {
let stream = BufReader::new(incoming.0); let stream = BufReader::new(incoming.0);
@@ -1453,7 +1454,7 @@ fn main() -> Result<()> {
socket.push("komorebic.sock"); socket.push("komorebic.sock");
let socket = socket.as_path(); let socket = socket.as_path();
match std::fs::remove_file(&socket) { match std::fs::remove_file(socket) {
Ok(_) => {} Ok(_) => {}
Err(error) => match error.kind() { Err(error) => match error.kind() {
// Doing this because ::exists() doesn't work reliably on Windows via IntelliJ // 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()?)?; send_message(&SocketMessage::SocketSchema.as_bytes()?)?;
let listener = UnixListener::bind(&socket)?; let listener = UnixListener::bind(socket)?;
match listener.accept() { match listener.accept() {
Ok(incoming) => { Ok(incoming) => {
let stream = BufReader::new(incoming.0); let stream = BufReader::new(incoming.0);