Skip to content

Commit

Permalink
Make Clippy happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwalters committed Jan 7, 2025
1 parent ac6724f commit 78028fb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/modules/builtin/cli/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ impl ParamKind {
return None;
}
}
if names.len() == 1 && (shorts.len() + longs.len()) == 0 {
let positionals = names.len();
let optionals = shorts.len() + longs.len();
if positionals == 1 && optionals == 0 {
let name = names.into_iter().next().unwrap();
Some(ParamKind::Positional(name))
} else if names.len() == 0 && (shorts.len() + longs.len()) >= 1 {
} else if positionals == 0 && optionals >= 1 {
Some(ParamKind::Optional(shorts, longs, false))
} else {
None
Expand Down Expand Up @@ -81,7 +83,7 @@ impl ParamImpl {
};
}

pub fn describe_optional(shorts: &Vec<char>, longs: &Vec<String>) -> String {
pub fn describe_optional(shorts: &[char], longs: &[String]) -> String {
let shorts = shorts.iter().map(|short| format!("-{short}"));
let longs = longs.iter().map(|long| format!("--{long}"));
shorts.chain(longs).join("|")
Expand Down
7 changes: 2 additions & 5 deletions src/modules/builtin/cli/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,8 @@ pub struct ParserCli {

impl ParserCli {
pub fn get_payload(&self) -> Option<Payload> {
if let Some(parser) = &self.parser {
Some(Payload::Parser(Rc::clone(parser)))
} else {
None
}
self.parser.as_ref()
.map(|parser| Payload::Parser(Rc::clone(parser)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/expression/literal/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct Text {

impl Text {
pub fn get_literal_text(&self) -> Option<String> {
if self.strings.len() == 1 && self.interps.len() == 0 {
self.strings.first().map(String::clone)
if self.strings.len() == 1 && self.interps.is_empty() {
self.strings.first().cloned()
} else {
None
}
Expand Down
12 changes: 5 additions & 7 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ fn extract_output(code: impl Into<String>) -> String {

fn trim_comment(line: &str) -> &str {
let mut chars = line.chars();
if chars.next() == Some('/') {
if chars.next() == Some('/') {
return if chars.next() == Some(' ') {
&line[3..]
} else {
&line[2..]
}
if chars.next() == Some('/') && chars.next() == Some('/') {
return if chars.next() == Some(' ') {
&line[3..]
} else {
&line[2..]
}
}
line
Expand Down
5 changes: 2 additions & 3 deletions src/utils/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ pub enum Payload {

impl Payload {
pub fn set_var_name(&mut self, name: &str, id: Option<usize>) {
match self {
Payload::Param(param) => param.borrow_mut().set_var_name(name, id),
_ => (),
if let Payload::Param(param) = self {
param.borrow_mut().set_var_name(name, id)
}
}
}

0 comments on commit 78028fb

Please sign in to comment.