Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clippy warnings #3853

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ use zellij_utils::{
pub(crate) fn get_sessions() -> Result<Vec<(String, Duration)>, io::ErrorKind> {
match fs::read_dir(&*ZELLIJ_SOCK_DIR) {
Ok(files) => {
let mut sessions = Vec::new();
files.for_each(|file| {
let file = file.unwrap();
let file_name = file.file_name().into_string().unwrap();
let ctime = std::fs::metadata(&file.path())
.ok()
.and_then(|f| f.created().ok())
.and_then(|d| d.elapsed().ok())
.unwrap_or_default();
let duration = Duration::from_secs(ctime.as_secs());
if file.file_type().unwrap().is_socket() && assert_socket(&file_name) {
sessions.push((file_name, duration));
}
});
let sessions: Vec<_> = files
.filter_map(|file| {
let file = file.ok()?;
let file_name = file.file_name().into_string().ok()?;
let duration = file.metadata().ok()?.created().ok()?.elapsed().ok()?;
if file.file_type().ok()?.is_socket() && assert_socket(&file_name) {
Some((file_name, Duration::from_secs(duration.as_secs())))
} else {
None
}
})
.collect();
Ok(sessions)
},
Err(err) if io::ErrorKind::NotFound != err.kind() => Err(err.kind()),
Expand Down
2 changes: 1 addition & 1 deletion zellij-utils/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ impl LayoutInfo {

use std::hash::{Hash, Hasher};

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for SessionInfo {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
Expand Down
20 changes: 9 additions & 11 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,16 @@ impl Action {
name,
)])
}
} else if floating {
Ok(vec![Action::NewFloatingPane(
None,
name,
FloatingPaneCoordinates::new(x, y, width, height),
)])
} else if in_place {
Ok(vec![Action::NewInPlacePane(None, name)])
} else {
if floating {
Ok(vec![Action::NewFloatingPane(
None,
name,
FloatingPaneCoordinates::new(x, y, width, height),
)])
} else if in_place {
Ok(vec![Action::NewInPlacePane(None, name)])
} else {
Ok(vec![Action::NewTiledPane(direction, None, name)])
}
Ok(vec![Action::NewTiledPane(direction, None, name)])
}
},
CliAction::Edit {
Expand Down
4 changes: 2 additions & 2 deletions zellij-utils/src/input/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl Run {
}
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Debug, Serialize, Deserialize, Clone, Hash, Default)]
pub struct RunPlugin {
#[serde(default)]
Expand Down Expand Up @@ -485,7 +485,7 @@ impl PluginAlias {
}
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl PartialEq for RunPlugin {
fn eq(&self, other: &Self) -> bool {
// TODO: normalize paths here if the location is a file so that relative/absolute paths
Expand Down
19 changes: 11 additions & 8 deletions zellij-utils/src/input/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ pub struct PluginConfig {

impl PluginConfig {
pub fn from_run_plugin(run_plugin: &RunPlugin) -> Option<PluginConfig> {
const BUILTIN_TAGS: &[&str] = &[
"status-bar",
"tab-bar",
"compact-bar",
"strider",
"session-manager",
"configuration",
"plugin-manager",
];

match &run_plugin.location {
RunPluginLocation::File(path) => Some(PluginConfig {
path: path.clone(),
Expand All @@ -57,14 +67,7 @@ impl PluginConfig {
}),
RunPluginLocation::Zellij(tag) => {
let tag = tag.to_string();
if tag == "status-bar"
|| tag == "tab-bar"
|| tag == "compact-bar"
|| tag == "strider"
|| tag == "session-manager"
|| tag == "configuration"
|| tag == "plugin-manager"
{
if BUILTIN_TAGS.contains(&tag.as_str()) {
Some(PluginConfig {
path: PathBuf::from(&tag),
_allow_exec_host_cmd: run_plugin._allow_exec_host_cmd,
Expand Down
99 changes: 37 additions & 62 deletions zellij-utils/src/kdl/kdl_layout_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,35 @@ impl<'a> KdlLayoutParser<'a> {
kdl_node: &KdlNode,
) -> Result<(), ConfigError> {
if name.is_empty() {
Err(ConfigError::new_layout_kdl_error(
format!("Template names cannot be empty"),
return Err(ConfigError::new_layout_kdl_error(
"Template names cannot be empty".into(),
kdl_node.span().offset(),
kdl_node.span().len(),
))
} else if name.contains(')') || name.contains('(') {
Err(ConfigError::new_layout_kdl_error(
format!("Template names cannot contain parantheses"),
));
}

if name.contains(')') || name.contains('(') {
return Err(ConfigError::new_layout_kdl_error(
"Template names cannot contain parentheses".into(),
kdl_node.span().offset(),
kdl_node.span().len(),
))
} else if name
));
}

if name
.chars()
.next()
.map(|first_char| first_char.is_numeric())
.unwrap_or(false)
{
Err(ConfigError::new_layout_kdl_error(
format!("Template names cannot start with numbers"),
return Err(ConfigError::new_layout_kdl_error(
"Template names cannot start with numbers".into(),
kdl_node.span().offset(),
kdl_node.span().len(),
))
} else {
Ok(())
));
}

Ok(())
}
fn assert_no_grandchildren_in_stack(
&self,
Expand Down Expand Up @@ -1962,60 +1966,31 @@ impl<'a> KdlLayoutParser<'a> {
Ok(())
}
fn parse_constraint(&mut self, layout_node: &KdlNode) -> Result<LayoutConstraint, ConfigError> {
if let Some(max_panes) = kdl_get_string_property_or_child_value!(layout_node, "max_panes") {
return Err(kdl_parsing_error!(
format!(
"max_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")",
max_panes
),
layout_node
));
};
if let Some(min_panes) = kdl_get_string_property_or_child_value!(layout_node, "min_panes") {
return Err(kdl_parsing_error!(
format!(
"min_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")",
min_panes
),
layout_node
));
};
if let Some(exact_panes) =
kdl_get_string_property_or_child_value!(layout_node, "exact_panes")
{
return Err(kdl_parsing_error!(
format!(
"exact_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")",
exact_panes,
),
layout_node
));
};
let max_panes = kdl_get_int_property_or_child_value!(layout_node, "max_panes");
let min_panes = kdl_get_int_property_or_child_value!(layout_node, "min_panes");
let exact_panes = kdl_get_int_property_or_child_value!(layout_node, "exact_panes");
let mut constraint_count = 0;
let mut constraint = None;
if let Some(max_panes) = max_panes {
constraint_count += 1;
constraint = Some(LayoutConstraint::MaxPanes(max_panes as usize));
}
if let Some(min_panes) = min_panes {
constraint_count += 1;
constraint = Some(LayoutConstraint::MinPanes(min_panes as usize));
}
if let Some(exact_panes) = exact_panes {
constraint_count += 1;
constraint = Some(LayoutConstraint::ExactPanes(exact_panes as usize));
}
if constraint_count > 1 {
let constraints: [(&str, fn(usize) -> LayoutConstraint); 3] = [
("max_panes", LayoutConstraint::MaxPanes),
("min_panes", LayoutConstraint::MinPanes),
("exact_panes", LayoutConstraint::ExactPanes),
];

let mut applied_constraints = vec![];
for (key, constructor) in constraints {
if let Some(value) = kdl_get_int_property_or_child_value!(layout_node, key) {
applied_constraints.push(constructor(value as usize));
}
}

if applied_constraints.len() > 1 {
return Err(kdl_parsing_error!(
format!("cannot have more than one constraint (eg. max_panes + min_panes)'"),
String::from("Cannot define multiple constraints (e.g., max_panes + min_panes)"),
layout_node
));
}
Ok(constraint.unwrap_or(LayoutConstraint::NoConstraint))

Ok(applied_constraints
.pop()
.unwrap_or(LayoutConstraint::NoConstraint))
}

fn populate_one_swap_tiled_layout(
&self,
layout_node: &KdlNode,
Expand Down
2 changes: 1 addition & 1 deletion zellij-utils/src/pane_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Display for Constraint {
}
}

#[allow(clippy::derive_hash_xor_eq)]
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for Constraint {
fn hash<H: Hasher>(&self, state: &mut H) {
match self {
Expand Down
6 changes: 3 additions & 3 deletions zellij-utils/src/plugin_api/plugin_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
PluginCommand::SwitchTabTo(tab_index) => Ok(ProtobufPluginCommand {
name: CommandName::SwitchTabTo as i32,
payload: Some(Payload::SwitchTabToPayload(SwitchTabToPayload {
tab_index: tab_index,
tab_index,
})),
}),
PluginCommand::SetTimeout(seconds) => Ok(ProtobufPluginCommand {
Expand Down Expand Up @@ -1644,7 +1644,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
Ok(ProtobufPluginCommand {
name: CommandName::FocusTerminalPane as i32,
payload: Some(Payload::FocusTerminalPanePayload(PaneIdAndShouldFloat {
pane_id: pane_id,
pane_id,
should_float: should_float_if_hidden,
})),
})
Expand All @@ -1653,7 +1653,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
Ok(ProtobufPluginCommand {
name: CommandName::FocusPluginPane as i32,
payload: Some(Payload::FocusPluginPanePayload(PaneIdAndShouldFloat {
pane_id: pane_id,
pane_id,
should_float: should_float_if_hidden,
})),
})
Expand Down