Skip to content

Commit a17a123

Browse files
committed
Fix all clippy warnings to pass CI checks
- Remove unnecessary casts (i64 -> i64) - Use .first() instead of .get(0) - Use .unwrap_or_default() instead of .unwrap_or_else(Vec::new) - Remove unnecessary .trim() before .split_whitespace() - Use .as_deref() instead of .as_ref().map(|x| x.as_str()) - Fix never_loop by using .first() instead of loop - Add allow attribute for recursion-only parameter
1 parent 6eecaa2 commit a17a123

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/app.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl BastionDropdownState {
7676
host.description.clone().unwrap_or_default()
7777
);
7878
if let Some(score) = matcher.fuzzy_match(&haystack, &self.search_filter) {
79-
scored.push((score as i64, i));
79+
scored.push((score, i));
8080
}
8181
}
8282
scored.sort_by(|a, b| b.0.cmp(&a.0));
@@ -415,7 +415,7 @@ impl FormState {
415415
f.cursor = f.cursor.min(f.value.len());
416416
}
417417
if matches!(self.kind, FormKind::Add) && self.index == 0 {
418-
if let Some(cmd_field) = self.fields.get(0) {
418+
if let Some(cmd_field) = self.fields.first() {
419419
if let Some(spec) =
420420
non_empty(&cmd_field.value).and_then(|s| parse_ssh_spec(&s).ok())
421421
{
@@ -530,15 +530,15 @@ impl FormState {
530530
.filter(|t| !t.is_empty())
531531
.collect()
532532
})
533-
.unwrap_or_else(Vec::new);
533+
.unwrap_or_default();
534534
let options = non_empty(options_field)
535535
.map(|s| {
536536
s.split_whitespace()
537537
.map(|t| t.trim().to_string())
538538
.filter(|t| !t.is_empty())
539539
.collect()
540540
})
541-
.unwrap_or_else(Vec::new);
541+
.unwrap_or_default();
542542
let remote_command = non_empty(remote_field);
543543
let description = non_empty(desc_field);
544544

@@ -636,9 +636,9 @@ fn parse_ssh_spec(input: &str) -> Result<SshSpec> {
636636
let mut key_path = None;
637637
let mut bastion = None;
638638
let mut options = Vec::new();
639-
let tokens: Vec<&str> = input.trim().split_whitespace().collect();
639+
let tokens: Vec<&str> = input.split_whitespace().collect();
640640
let mut i = 0usize;
641-
if tokens.get(0) == Some(&"ssh") {
641+
if tokens.first() == Some(&"ssh") {
642642
i += 1;
643643
}
644644

@@ -1178,7 +1178,7 @@ impl App {
11781178
host.description.clone().unwrap_or_default()
11791179
);
11801180
if let Some(score) = self.matcher.fuzzy_match(&haystack, &self.filter) {
1181-
scored.push((score as i64, i));
1181+
scored.push((score, i));
11821182
}
11831183
}
11841184
scored.sort_by(|a, b| b.0.cmp(&a.0));
@@ -1323,11 +1323,11 @@ impl App {
13231323
fn find_host_by_spec(&self, spec: &SshSpec) -> Option<usize> {
13241324
self.config.hosts.iter().position(|h| {
13251325
h.address == spec.address
1326-
&& h.user.as_ref().map(|u| u.as_str()) == spec.user.as_deref()
1326+
&& h.user.as_deref() == spec.user.as_deref()
13271327
&& h.port == spec.port
13281328
&& h.options == spec.options
1329-
&& h.bastion.as_ref().map(|b| b.as_str()) == spec.bastion.as_deref()
1330-
&& h.remote_command.as_ref().map(|c| c.as_str()) == spec.remote_command.as_deref()
1329+
&& h.bastion.as_deref() == spec.bastion.as_deref()
1330+
&& h.remote_command.as_deref() == spec.remote_command.as_deref()
13311331
})
13321332
}
13331333

src/ssh.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub fn command_preview(
109109
parts.join(" ")
110110
}
111111

112+
#[allow(clippy::only_used_in_recursion)]
112113
fn build_bastion_string(
113114
config: &Config,
114115
bastion_name: &str,
@@ -167,7 +168,7 @@ fn select_key(host_key: Option<&str>, default_key: Option<&str>) -> Option<Strin
167168
}
168169

169170
// fall back to common keys when no agent is present
170-
for cand in FALLBACKS {
171+
if let Some(cand) = FALLBACKS.first() {
171172
return Some(expand_tilde(cand));
172173
}
173174
None

src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ fn render_modal_form(
497497
.add_modifier(Modifier::BOLD),
498498
)));
499499
line_no += 1;
500-
if let Some(f) = form.fields.get(0) {
500+
if let Some(f) = form.fields.first() {
501501
let active = form.index == 0;
502502
rows.push(Line::from(vec![
503503
Span::styled(

0 commit comments

Comments
 (0)