WalkerCodeRanger/semver

"!=" Comparison for Version Ranges

Opened this issue · 3 comments

The "!=" comparison currently isn't implemented for version ranges. However, some popular tools like Helm allow this comparison. More specifically, Helm allows "!=" comparisons when using the semverCompare template function.

I think that we should add support for a "!=" comparison.

Example

Imagine that you are trying to check if a version range is a valid version range for Helm. You can create code similar to the following:

public static bool IsValidHelmRange(string range) {
    return SemVersionRange.TryParseNpm(range, out _);
}

When passing !=1.0.0 for range, this method returns false. However, we would want it to return true in this case since the version range is valid for Helm.

I think that we can add an option to SemVersionRangeOptions. Thoughts?

The SemVersionRange.TryParseNpm function is specifically meant to match npm supported range syntax. I wouldn't expect it to support any other syntax.

Unfortunately, adding support for != to the standard range syntax (i.e. SemVersionRange.TryParse(range, out _)) isn't as straightforward as you might think. The problem is that the underlying representation of ranges is built around continuous ranges (UnbrokenSemVersionRange) that don't work with !=. Hence, it isn't just a matter of adding another option to SemVersionRangeOptions. That said, it may be possible to support with enough work. It won't be in the next 2.3.0 release, but I'll leave this issue open to see if it can be supported after the 3.0 release.