semver: run v fmt (#7439)
parent
805ec8e177
commit
fade162471
|
@ -3,9 +3,7 @@ module semver
|
|||
// * Private functions.
|
||||
[inline]
|
||||
fn version_satisfies(ver Version, input string) bool {
|
||||
range := parse_range(input) or {
|
||||
return false
|
||||
}
|
||||
range := parse_range(input) or { return false }
|
||||
return range.satisfies(ver)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,12 @@ fn parse(input string) RawVersion {
|
|||
mut raw_version := input
|
||||
mut prerelease := ''
|
||||
mut metadata := ''
|
||||
plus_idx := raw_version.last_index('+') or {
|
||||
-1
|
||||
}
|
||||
plus_idx := raw_version.last_index('+') or { -1 }
|
||||
if plus_idx > 0 {
|
||||
metadata = raw_version[(plus_idx + 1)..]
|
||||
raw_version = raw_version[0..plus_idx]
|
||||
}
|
||||
hyphen_idx := raw_version.index('-') or {
|
||||
-1
|
||||
}
|
||||
hyphen_idx := raw_version.index('-') or { -1 }
|
||||
if hyphen_idx > 0 {
|
||||
prerelease = raw_version[(hyphen_idx + 1)..]
|
||||
raw_version = raw_version[0..hyphen_idx]
|
||||
|
|
|
@ -61,14 +61,10 @@ fn parse_range(input string) ?Range {
|
|||
mut comparator_sets := []ComparatorSet{}
|
||||
for raw_comp_set in raw_comparator_sets {
|
||||
if can_expand(raw_comp_set) {
|
||||
s := expand_comparator_set(raw_comp_set) or {
|
||||
return error(err)
|
||||
}
|
||||
s := expand_comparator_set(raw_comp_set) or { return error(err) }
|
||||
comparator_sets << s
|
||||
} else {
|
||||
s := parse_comparator_set(raw_comp_set) or {
|
||||
return error(err)
|
||||
}
|
||||
s := parse_comparator_set(raw_comp_set) or { return error(err) }
|
||||
comparator_sets << s
|
||||
}
|
||||
}
|
||||
|
@ -82,9 +78,7 @@ fn parse_comparator_set(input string) ?ComparatorSet {
|
|||
}
|
||||
mut comparators := []Comparator{}
|
||||
for raw_comp in raw_comparators {
|
||||
c := parse_comparator(raw_comp) or {
|
||||
return error('Invalid comparator: $raw_comp')
|
||||
}
|
||||
c := parse_comparator(raw_comp) or { return error('Invalid comparator: $raw_comp') }
|
||||
comparators << c
|
||||
}
|
||||
return ComparatorSet{comparators}
|
||||
|
@ -110,9 +104,7 @@ fn parse_comparator(input string) ?Comparator {
|
|||
} else {
|
||||
raw_version = input
|
||||
}
|
||||
version := coerce_version(raw_version) or {
|
||||
return none
|
||||
}
|
||||
version := coerce_version(raw_version) or { return none }
|
||||
return Comparator{version, op}
|
||||
}
|
||||
|
||||
|
@ -162,9 +154,7 @@ fn expand_comparator_set(input string) ?ComparatorSet {
|
|||
}
|
||||
|
||||
fn expand_tilda(raw_version string) ?ComparatorSet {
|
||||
min_ver := coerce_version(raw_version) or {
|
||||
return none
|
||||
}
|
||||
min_ver := coerce_version(raw_version) or { return none }
|
||||
mut max_ver := min_ver
|
||||
if min_ver.minor == 0 && min_ver.patch == 0 {
|
||||
max_ver = min_ver.increment(.major)
|
||||
|
@ -175,9 +165,7 @@ fn expand_tilda(raw_version string) ?ComparatorSet {
|
|||
}
|
||||
|
||||
fn expand_caret(raw_version string) ?ComparatorSet {
|
||||
min_ver := coerce_version(raw_version) or {
|
||||
return none
|
||||
}
|
||||
min_ver := coerce_version(raw_version) or { return none }
|
||||
mut max_ver := min_ver
|
||||
if min_ver.major == 0 {
|
||||
max_ver = min_ver.increment(.minor)
|
||||
|
@ -192,16 +180,12 @@ fn expand_hyphen(raw_range string) ?ComparatorSet {
|
|||
if raw_versions.len != 2 {
|
||||
return none
|
||||
}
|
||||
min_ver := coerce_version(raw_versions[0]) or {
|
||||
return none
|
||||
}
|
||||
min_ver := coerce_version(raw_versions[0]) or { return none }
|
||||
raw_max_ver := parse(raw_versions[1])
|
||||
if raw_max_ver.is_missing(ver_major) {
|
||||
return none
|
||||
}
|
||||
mut max_ver := raw_max_ver.coerce() or {
|
||||
return none
|
||||
}
|
||||
mut max_ver := raw_max_ver.coerce() or { return none }
|
||||
if raw_max_ver.is_missing(ver_minor) {
|
||||
max_ver = max_ver.increment(.minor)
|
||||
return make_comparator_set_ge_lt(min_ver, max_ver)
|
||||
|
@ -210,9 +194,7 @@ fn expand_hyphen(raw_range string) ?ComparatorSet {
|
|||
}
|
||||
|
||||
fn expand_xrange(raw_range string) ?ComparatorSet {
|
||||
min_ver := parse_xrange(raw_range) or {
|
||||
return none
|
||||
}
|
||||
min_ver := parse_xrange(raw_range) or { return none }
|
||||
if min_ver.major == 0 {
|
||||
comparators := [
|
||||
Comparator{min_ver, Operator.ge},
|
||||
|
|
|
@ -26,9 +26,7 @@ pub fn from(input string) ?Version {
|
|||
return error('Empty input')
|
||||
}
|
||||
raw_version := parse(input)
|
||||
version := raw_version.validate() or {
|
||||
return error('Invalid version format')
|
||||
}
|
||||
version := raw_version.validate() or { return error('Invalid version format') }
|
||||
return version
|
||||
}
|
||||
|
||||
|
@ -71,9 +69,7 @@ pub fn (v1 Version) le(v2 Version) bool {
|
|||
|
||||
// * Utilites.
|
||||
pub fn coerce(input string) ?Version {
|
||||
ver := coerce_version(input) or {
|
||||
return error('Invalid version: $input')
|
||||
}
|
||||
ver := coerce_version(input) or { return error('Invalid version: $input') }
|
||||
return ver
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ fn is_version_valid(input string) bool {
|
|||
[inline]
|
||||
fn coerce_version(input string) ?Version {
|
||||
raw_ver := parse(input)
|
||||
ver := raw_ver.coerce() or {
|
||||
return error('Invalid version: $input')
|
||||
}
|
||||
ver := raw_ver.coerce() or { return error('Invalid version: $input') }
|
||||
return ver
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue