Skip to content

Commit f7be01e

Browse files
style: add .golangci-lint.yaml
1 parent 7878460 commit f7be01e

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

.golangci.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
linters:
2+
enable:
3+
- errorlint
4+
- forbidigo
5+
- gochecknoinits
6+
- gocritic
7+
- goconst
8+
- gocyclo
9+
- gofumpt
10+
- goimports
11+
- misspell
12+
- revive
13+
- unconvert
14+
- unparam
15+
- wastedassign
16+
17+
linters-settings:
18+
gocyclo:
19+
min-complexity: 12
20+
gofumpt:
21+
extra-rules: true
22+
govet:
23+
enable-all: true
24+
disable:
25+
- fieldalignment

pkg/provider/git.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ func (repo *Repository) Init(config map[string]string) error {
5252
config["auth_username"] = "git"
5353
}
5454

55-
if config["auth"] == "basic" {
55+
switch config["auth"] {
56+
case "basic":
5657
repo.auth = &http.BasicAuth{
5758
Username: config["auth_username"],
5859
Password: config["auth_password"],
5960
}
60-
} else if config["auth"] == "ssh" {
61+
case "ssh":
6162
auth, err := ssh.NewPublicKeysFromFile(config["auth_username"], config["auth_private_key"], config["auth_password"])
6263
if err != nil {
6364
return err
6465
}
6566
repo.auth = auth
66-
} else {
67+
default:
6768
repo.auth = nil
6869
}
6970

@@ -137,15 +138,15 @@ func (repo *Repository) GetReleases(rawRe string) ([]*semrel.Release, error) {
137138
if rawRe != "" && !re.MatchString(tag) {
138139
return nil
139140
}
140-
version, err := semver.NewVersion(tag)
141-
if err != nil {
141+
version, semverErr := semver.NewVersion(tag)
142+
if semverErr != nil {
142143
return nil
143144
}
144145

145146
// resolve annotated tags
146147
sha := reference.Hash()
147-
if tagObj, err := repo.repo.TagObject(sha); err == nil {
148-
if com, err := tagObj.Commit(); err == nil {
148+
if tagObj, tagErr := repo.repo.TagObject(sha); tagErr == nil {
149+
if com, commitErr := tagObj.Commit(); commitErr == nil {
149150
sha = com.Hash
150151
}
151152
}

pkg/provider/git_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package provider
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"os"
66
"strings"
77
"testing"
88
"time"
@@ -53,8 +53,9 @@ func newRepository(t *testing.T) {
5353
require.NotNil(repo.auth)
5454
}
5555

56+
//gocyclo:ignore
5657
func setupRepo() (string, error) {
57-
dir, err := ioutil.TempDir("", "provider-git")
58+
dir, err := os.MkdirTemp("", "provider-git")
5859
if err != nil {
5960
return "", err
6061
}
@@ -83,19 +84,19 @@ func setupRepo() (string, error) {
8384
versionCount := 0
8485
betaCount := 1
8586
for i := 0; i < 100; i++ {
86-
commit, err := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author})
87-
if err != nil {
87+
commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author, AllowEmptyCommits: true})
88+
if commitErr != nil {
8889
return "", err
8990
}
9091
if i%10 == 0 {
91-
if _, err := repo.CreateTag(fmt.Sprintf("v1.%d.0", versionCount), commit, nil); err != nil {
92-
return "", err
92+
if _, tagErr := repo.CreateTag(fmt.Sprintf("v1.%d.0", versionCount), commit, nil); tagErr != nil {
93+
return "", tagErr
9394
}
9495
versionCount++
9596
}
9697
if i%5 == 0 {
97-
if _, err := repo.CreateTag(fmt.Sprintf("v2.0.0-beta.%d", betaCount), commit, nil); err != nil {
98-
return "", err
98+
if _, tagErr := repo.CreateTag(fmt.Sprintf("v2.0.0-beta.%d", betaCount), commit, nil); tagErr != nil {
99+
return "", tagErr
99100
}
100101
betaCount++
101102
}
@@ -109,7 +110,7 @@ func setupRepo() (string, error) {
109110
return "", err
110111
}
111112

112-
if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author}); err != nil {
113+
if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author, AllowEmptyCommits: true}); err != nil {
113114
return "", err
114115
}
115116
if err = w.Checkout(&git.CheckoutOptions{Branch: plumbing.NewBranchReferenceName("master")}); err != nil {

0 commit comments

Comments
 (0)