Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minor version check for caret (^) when minor version in constraint is 0(zero) #181

Merged
merged 4 commits into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions .golangci.yml
Expand Up @@ -4,23 +4,27 @@ run:
linters:
disable-all: true
enable:
- misspell
- structcheck
- govet
- staticcheck
- deadcode
- dupl
- errcheck
- gofmt
- goimports
- golint
- gosimple
- govet
- varcheck
- unparam
- ineffassign
- misspell
- nakedret
- structcheck
- gocyclo
- dupl
- goimports
- revive
- gosec
- gosimple
- typecheck
- unused
- varcheck

linters-settings:
gofmt:
simplify: true
dupl:
threshold: 400
threshold: 600
4 changes: 4 additions & 0 deletions constraints.go
Expand Up @@ -534,6 +534,10 @@ func constraintCaret(v *Version, c *constraint) (bool, error) {
}
return false, fmt.Errorf("%s does not have same minor version as %s. Expected minor versions to match when constraint major version is 0", v, c.orig)
}
// ^ when the minor is 0 and minor > 0 is =0.0.z
if c.con.Minor() == 0 && v.Minor() > 0 {
return false, fmt.Errorf("%s does not have same minor version as %s", v, c.orig)
}

// At this point the major is 0 and the minor is 0 and not dirty. The patch
// is not dirty so we need to check if they are equal. If they are not equal
Expand Down
4 changes: 3 additions & 1 deletion constraints_test.go
Expand Up @@ -362,6 +362,8 @@ func TestConstraintsCheck(t *testing.T) {
{"^1.x", "1.1.1-beta1", false},
{"^1.1.2-alpha", "1.2.1-beta1", true},
{"^1.2.x-alpha", "1.1.1-beta1", false},
{"^0.0.1", "0.0.1", true},
{"^0.0.1", "0.3.1", false},
{"~*", "2.1.1", true},
{"~1", "2.1.1", false},
{"~1", "1.3.5", true},
Expand Down Expand Up @@ -598,7 +600,7 @@ func TestConstraintsValidate(t *testing.T) {
{"^1.x", "2.1.1", "2.1.1 does not have same major version as 1.x"},
{"^0.2", "0.3.0", "0.3.0 does not have same minor version as 0.2. Expected minor versions to match when constraint major version is 0"},
{"^0.2", "0.1.1", "0.1.1 is less than 0.2"},
{"^0.0.3", "0.1.1", "0.1.1 does not equal 0.0.3. Expect version and constraint to equal when major and minor versions are 0"},
{"^0.0.3", "0.1.1", "0.1.1 does not have same minor version as 0.0.3"},
{"^0.0.3", "0.0.4", "0.0.4 does not equal 0.0.3. Expect version and constraint to equal when major and minor versions are 0"},
{"^0.0.3", "0.0.2", "0.0.2 is less than 0.0.3"},
{"~1", "2.1.2", "2.1.2 does not have same major version as 1"},
Expand Down