Skip to content

Commit

Permalink
refactor(clippy): apply various lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Nov 13, 2022
1 parent b010215 commit 37edbcf
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 51 deletions.
4 changes: 2 additions & 2 deletions komorebi-core/src/config_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down Expand Up @@ -168,7 +168,7 @@ impl ApplicationConfigurationGenerator {
}
}

lines.push(String::from(""));
lines.push(String::new());
}

Ok(lines)
Expand Down
34 changes: 14 additions & 20 deletions komorebi-core/src/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,33 +229,27 @@ 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 {
return false;
}

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,
})
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions komorebi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ lazy_static! {
static ref HIDING_BEHAVIOUR: Arc<Mutex<HidingBehaviour>> =
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() {
Expand All @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions komorebi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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())?;
}
};
Expand Down
43 changes: 22 additions & 21 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -1192,7 +1193,7 @@ fn main() -> Result<()> {
},
};

let listener = UnixListener::bind(&socket)?;
let listener = UnixListener::bind(socket)?;

send_message(&SocketMessage::State.as_bytes()?)?;

Expand All @@ -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
Expand All @@ -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()?)?;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 37edbcf

Please sign in to comment.