Skip to content

Commit

Permalink
Fix clippy errors except for the false positive described in rust-lan…
Browse files Browse the repository at this point in the history
  • Loading branch information
GJKrupa committed Oct 4, 2023
1 parent a757a77 commit aee849c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ fn main() {

for version in candidate.versions {
let the_match = version.get_matching(name.clone(), available.clone());
the_match.map(|it| {
if let Some(it) = the_match {
required.insert(it.to_string());
if version.default.unwrap_or(false) {
default = Some(it.to_string());
}
});
}
}

let to_install = required.difference(&installed);
Expand Down
9 changes: 3 additions & 6 deletions src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait VersionMatch {
impl VersionMatch for Version {
fn get_matching(&self, name: String, available: Vec<String>) -> Option<String> {
let pattern = Regex::new(self.pattern.as_str())
.expect(format!("Invalid regex for {}: {}", name, self.pattern).as_str());
.unwrap_or_else(|_| panic!("Invalid regex for {}: {}", name, self.pattern));
let mut matches: Vec<String> = available
.iter()
.filter(|it| pattern.is_match(it))
Expand All @@ -41,11 +41,8 @@ impl VersionMatch for Version {

if let Some(exclude) = self.exclude.as_ref() {
let exclude_pattern = Regex::new(exclude.join("|").as_str())
.expect(format!("Invalid regex for {}: {}", name, exclude.join("|")).as_str());
matches = matches
.into_iter()
.filter(|it| !exclude_pattern.is_match(it))
.collect();
.unwrap_or_else(|_| panic!("Invalid regex for {}: {}", name, exclude.join("|")));
matches.retain(|it| !exclude_pattern.is_match(it));
}

return matches.first().map(|it| it.to_string());
Expand Down
7 changes: 4 additions & 3 deletions src/sdkman/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ mod private {
} else if dashes_pattern.is_match(line) {
dashes += 1;
} else if equals == 2 && dashes == 1 {
line.split_whitespace()
if let Some(word) = line.split_whitespace()
.filter(|word| *word != "*" && *word != ">")
.last()
.map(|word| versions.push(word.to_string()));
.last() {
versions.push(word.to_string());
}
}
}
versions
Expand Down
1 change: 1 addition & 0 deletions src/sdkman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct SdkMan {
}

impl ToolManager for SdkMan {
#[allow(clippy::needless_return)]
fn installed_versions(&self, candidate: String) -> Vec<String> {
return match env::var("SDKMAN_DIR") {
Ok(dir) => {
Expand Down

0 comments on commit aee849c

Please sign in to comment.