diff options
Diffstat (limited to 'crates/shirabe-semver')
6 files changed, 47 insertions, 67 deletions
diff --git a/crates/shirabe-semver/src/constraint/constraint.rs b/crates/shirabe-semver/src/constraint/constraint.rs index 8db322d..f8ff04e 100644 --- a/crates/shirabe-semver/src/constraint/constraint.rs +++ b/crates/shirabe-semver/src/constraint/constraint.rs @@ -347,10 +347,10 @@ impl ConstraintInterface for Constraint { } fn get_pretty_string(&self) -> String { - if let Some(ref s) = self.pretty_string { - if !s.is_empty() { - return s.clone(); - } + if let Some(ref s) = self.pretty_string + && !s.is_empty() + { + return s.clone(); } self.__to_string() } diff --git a/crates/shirabe-semver/src/constraint/match_all_constraint.rs b/crates/shirabe-semver/src/constraint/match_all_constraint.rs index b6b2445..97ce98c 100644 --- a/crates/shirabe-semver/src/constraint/match_all_constraint.rs +++ b/crates/shirabe-semver/src/constraint/match_all_constraint.rs @@ -22,10 +22,10 @@ impl ConstraintInterface for MatchAllConstraint { } fn get_pretty_string(&self) -> String { - if let Some(ref s) = self.pretty_string { - if !s.is_empty() { - return s.clone(); - } + if let Some(ref s) = self.pretty_string + && !s.is_empty() + { + return s.clone(); } self.__to_string() } diff --git a/crates/shirabe-semver/src/constraint/match_none_constraint.rs b/crates/shirabe-semver/src/constraint/match_none_constraint.rs index 17a45bb..51e13fd 100644 --- a/crates/shirabe-semver/src/constraint/match_none_constraint.rs +++ b/crates/shirabe-semver/src/constraint/match_none_constraint.rs @@ -22,10 +22,10 @@ impl ConstraintInterface for MatchNoneConstraint { } fn get_pretty_string(&self) -> String { - if let Some(ref s) = self.pretty_string { - if !s.is_empty() { - return s.clone(); - } + if let Some(ref s) = self.pretty_string + && !s.is_empty() + { + return s.clone(); } self.__to_string() } diff --git a/crates/shirabe-semver/src/constraint/multi_constraint.rs b/crates/shirabe-semver/src/constraint/multi_constraint.rs index 29d6f5e..04e262b 100644 --- a/crates/shirabe-semver/src/constraint/multi_constraint.rs +++ b/crates/shirabe-semver/src/constraint/multi_constraint.rs @@ -270,10 +270,10 @@ impl ConstraintInterface for MultiConstraint { } fn get_pretty_string(&self) -> String { - if let Some(ref s) = self.pretty_string { - if !s.is_empty() { - return s.clone(); - } + if let Some(ref s) = self.pretty_string + && !s.is_empty() + { + return s.clone(); } self.__to_string() } diff --git a/crates/shirabe-semver/src/intervals.rs b/crates/shirabe-semver/src/intervals.rs index be7466e..898cab3 100644 --- a/crates/shirabe-semver/src/intervals.rs +++ b/crates/shirabe-semver/src/intervals.rs @@ -393,11 +393,7 @@ impl Intervals { if branches.exclude { // disjunctive constraint, so only exclude what's excluded in all constraints // !=a,!=b || !=b,!=c => !=b - branches.names = branches - .names - .into_iter() - .filter(|n| b.names.contains(n)) - .collect(); + branches.names.retain(|n| b.names.contains(n)); } else { // disjunctive constraint so exclude all names which are not explicitly // included in the alternative @@ -414,11 +410,7 @@ impl Intervals { // disjunctive constraint so exclude all names which are not explicitly // included in the alternative // !=a,!=b || (==b || ==c) => !=a - branches.names = branches - .names - .into_iter() - .filter(|n| !b.names.contains(n)) - .collect(); + branches.names.retain(|n| !b.names.contains(n)); } else { // disjunctive constraint, so just add all the other branches // (==a || ==b) || ==c => ==a || ==b || ==c @@ -438,11 +430,7 @@ impl Intervals { } else { // conjunctive, so only keep included names which are not excluded // (==a||==c) && !=a,!=b => ==c - branches.names = branches - .names - .into_iter() - .filter(|n| !b.names.contains(n)) - .collect(); + branches.names.retain(|n| !b.names.contains(n)); } } else { if branches.exclude { @@ -457,11 +445,7 @@ impl Intervals { } else { // conjunctive, so only keep names that are included in both // (==a||==b) && (==a||==c) => ==a - branches.names = branches - .names - .into_iter() - .filter(|n| b.names.contains(n)) - .collect(); + branches.names.retain(|n| b.names.contains(n)); } } } diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs index 95149af..2c3bcc9 100644 --- a/crates/shirabe-semver/src/version_parser.rs +++ b/crates/shirabe-semver/src/version_parser.rs @@ -191,10 +191,10 @@ impl VersionParser { // a branch ending with -dev is only valid if it is numeric // if it gets prefixed with dev- it means the branch name should // have had a dev- prefix already when passed to normalize - if let Ok(normalized) = self.normalize_branch(&branch_name) { - if !normalized.starts_with("dev-") { - return Ok(normalized); - } + if let Ok(normalized) = self.normalize_branch(&branch_name) + && !normalized.starts_with("dev-") + { + return Ok(normalized); } } @@ -599,8 +599,7 @@ impl VersionParser { )?; // PHP's empty() on "0" returns true, but here we only check for truly empty/missing - let empty = - |x: &Option<String>| -> bool { x.as_deref().map_or(true, |s| s.is_empty()) }; + let empty = |x: &Option<String>| -> bool { x.as_deref().is_none_or(|s| s.is_empty()) }; // matches[12]=to minor, matches[13]=to patch, matches[15]=to stability, // matches[17]=to dev, matches[18]=to wildcard-dev @@ -645,37 +644,34 @@ impl VersionParser { let version_str = match_[2].clone().unwrap_or_default(); let op_str = match_[1].clone().unwrap_or_default(); - let version_result: anyhow::Result<String> = (|| { - match self.normalize(&version_str, None) { - Ok(v) => Ok(v), - Err(e) => { - // recover from an invalid constraint like foobar-dev which should be - // dev-foobar except if the constraint uses a known operator, in which - // case it must be a parse error - if version_str.ends_with("-dev") - && php::preg_match("{^[0-9a-zA-Z-./]+$}", &version_str, &mut Vec::new()) - > 0 - { - self.normalize( - &format!("dev-{}", &version_str[..version_str.len() - 4]), - None, - ) - } else { - Err(e) - } + let version_result: anyhow::Result<String> = (match self.normalize(&version_str, None) { + Ok(v) => Ok(v), + Err(e) => { + // recover from an invalid constraint like foobar-dev which should be + // dev-foobar except if the constraint uses a known operator, in which + // case it must be a parse error + if version_str.ends_with("-dev") + && php::preg_match("{^[0-9a-zA-Z-./]+$}", &version_str, &mut Vec::new()) > 0 + { + self.normalize( + &format!("dev-{}", &version_str[..version_str.len() - 4]), + None, + ) + } else { + Err(e) } } - })(); + }); if let Ok(mut version) = version_result { let op = if op_str.is_empty() { "=" } else { &op_str }; - if op != "==" && op != "=" { - if let Some(ref stab_mod) = stability_modifier { - if Self::parse_stability(&version) == "stable" { - version = format!("{}-{}", version, stab_mod); - } - } + if op != "==" + && op != "=" + && let Some(ref stab_mod) = stability_modifier + && Self::parse_stability(&version) == "stable" + { + version = format!("{}-{}", version, stab_mod); } if op == "<" || op == ">=" { let modifier_pattern = format!("{{-{}$}}", MODIFIER_REGEX); |
