Date: Tue, 24 Oct 2023 04:54:59 +0200
Subject: [PATCH 5/6] Upgrade to golangci-lint@v1.55.0 (#27756)
https://github.com/golangci/golangci-lint/releases/tag/v1.55.0
---
Makefile | 2 +-
models/actions/task.go | 2 +-
models/activities/action.go | 3 +-
models/issues/review.go | 3 +-
modules/activitypub/user_settings.go | 7 +-
modules/git/submodule.go | 3 +-
modules/lfs/transferadapter_test.go | 5 +-
modules/markup/html_test.go | 130 +++++++++++------------
modules/markup/markdown/markdown_test.go | 36 +++----
modules/templates/htmlrenderer.go | 3 +-
modules/util/path.go | 3 +-
routers/api/v1/repo/pull.go | 3 +-
routers/web/repo/cherry_pick.go | 5 +-
routers/web/repo/issue_dependency.go | 5 +-
routers/web/repo/patch.go | 5 +-
services/mailer/mailer.go | 3 +-
services/repository/files/temp_repo.go | 3 +-
tests/integration/integration_test.go | 3 +-
18 files changed, 105 insertions(+), 119 deletions(-)
diff --git a/Makefile b/Makefile
index 8e03a71b8d464..c38e88a8e0ad9 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ XGO_VERSION := go-1.21.x
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.44.0
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.5.0
-GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1
+GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
diff --git a/models/actions/task.go b/models/actions/task.go
index 69f52cf0846cf..db0031b3b8d3c 100644
--- a/models/actions/task.go
+++ b/models/actions/task.go
@@ -279,7 +279,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
return nil, false, fmt.Errorf("parse workflow of job %d: %w", job.ID, err)
} else if len(gots) != 1 {
return nil, false, fmt.Errorf("workflow of job %d: not single workflow", job.ID)
- } else {
+ } else { //nolint:revive
_, workflowJob = gots[0].Job()
}
diff --git a/models/activities/action.go b/models/activities/action.go
index 1bfd62438bf2a..15bd9a52acc5c 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -713,9 +713,8 @@ func DeleteIssueActions(ctx context.Context, repoID, issueID, issueIndex int64)
break
} else if _, err = db.GetEngine(ctx).In("comment_id", commentIDs).Delete(&Action{}); err != nil {
return err
- } else {
- lastCommentID = commentIDs[len(commentIDs)-1]
}
+ lastCommentID = commentIDs[len(commentIDs)-1]
}
_, err := e.Where("repo_id = ?", repoID).
diff --git a/models/issues/review.go b/models/issues/review.go
index 8b64ba8048989..1cb5379b2f6ec 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -213,9 +213,8 @@ func GetReviewByID(ctx context.Context, id int64) (*Review, error) {
return nil, err
} else if !has {
return nil, ErrReviewNotExist{ID: id}
- } else {
- return review, nil
}
+ return review, nil
}
// CreateReviewOptions represent the options to create a review. Type, Issue and Reviewer are required.
diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go
index d196a3806e7c4..7f939af352abe 100644
--- a/modules/activitypub/user_settings.go
+++ b/modules/activitypub/user_settings.go
@@ -29,11 +29,10 @@ func GetKeyPair(ctx context.Context, user *user_model.User) (pub, priv string, e
return pub, priv, err
}
return pub, priv, err
- } else {
- priv = settings[user_model.UserActivityPubPrivPem].SettingValue
- pub = settings[user_model.UserActivityPubPubPem].SettingValue
- return pub, priv, err
}
+ priv = settings[user_model.UserActivityPubPrivPem].SettingValue
+ pub = settings[user_model.UserActivityPubPubPem].SettingValue
+ return pub, priv, err
}
// GetPublicKey function returns a user's public key
diff --git a/modules/git/submodule.go b/modules/git/submodule.go
index 3afaa334dbca5..37813ea4c7ca5 100644
--- a/modules/git/submodule.go
+++ b/modules/git/submodule.go
@@ -101,9 +101,8 @@ func getRefURL(refURL, urlPrefix, repoFullName, sshDomain string) string {
return ref.Scheme + "://" + ref.Host + ref.Path
} else if urlPrefixHostname == refHostname || refHostname == sshDomain {
return urlPrefix + path.Clean(path.Join("/", ref.Path))
- } else {
- return "http://" + refHostname + ref.Path
}
+ return "http://" + refHostname + ref.Path
}
}
diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go
index f86d2c54beddb..6023cd07d32fd 100644
--- a/modules/lfs/transferadapter_test.go
+++ b/modules/lfs/transferadapter_test.go
@@ -62,10 +62,9 @@ func TestBasicTransferAdapter(t *testing.T) {
json.NewEncoder(payload).Encode(er)
return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(payload)}
- } else {
- t.Errorf("Unknown test case: %s", url)
- return nil
}
+ t.Errorf("Unknown test case: %s", url)
+ return nil
}
hc := &http.Client{Transport: RoundTripFunc(roundTripHandler)}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 9156bc63312b6..21bfc8314a8eb 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -14,7 +14,7 @@ import (
"code.gitea.io/gitea/modules/emoji"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
- . "code.gitea.io/gitea/modules/markup"
+ "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -37,12 +37,12 @@ func TestMain(m *testing.M) {
}
func TestRender_Commits(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
test := func(input, expected string) {
- buffer, err := RenderString(&RenderContext{
+ buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: ".md",
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
Metas: localMetas,
}, input)
assert.NoError(t, err)
@@ -50,7 +50,7 @@ func TestRender_Commits(t *testing.T) {
}
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
- repo := TestRepoURL
+ repo := markup.TestRepoURL
commit := util.URLJoin(repo, "commit", sha)
tree := util.URLJoin(repo, "tree", sha, "src")
@@ -87,10 +87,10 @@ func TestRender_Commits(t *testing.T) {
}
func TestRender_CrossReferences(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
test := func(input, expected string) {
- buffer, err := RenderString(&RenderContext{
+ buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
URLPrefix: setting.AppSubURL,
@@ -102,43 +102,43 @@ func TestRender_CrossReferences(t *testing.T) {
test(
"gogits/gogs#12345",
- `gogits/gogs#12345
`)
+ `gogits/gogs#12345
`)
test(
"go-gitea/gitea#12345",
- `go-gitea/gitea#12345
`)
+ `go-gitea/gitea#12345
`)
test(
"/home/gitea/go-gitea/gitea#12345",
`/home/gitea/go-gitea/gitea#12345
`)
test(
- util.URLJoin(TestAppURL, "gogitea", "gitea", "issues", "12345"),
- `gogitea/gitea#12345
`)
+ util.URLJoin(markup.TestAppURL, "gogitea", "gitea", "issues", "12345"),
+ `gogitea/gitea#12345
`)
test(
- util.URLJoin(TestAppURL, "go-gitea", "gitea", "issues", "12345"),
- `go-gitea/gitea#12345
`)
+ util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345"),
+ `go-gitea/gitea#12345
`)
test(
- util.URLJoin(TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
- `gogitea/some-repo-name#12345
`)
+ util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
+ `gogitea/some-repo-name#12345
`)
}
func TestMisc_IsSameDomain(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
sha := "b6dd6210eaebc915fd5be5579c58cce4da2e2579"
- commit := util.URLJoin(TestRepoURL, "commit", sha)
+ commit := util.URLJoin(markup.TestRepoURL, "commit", sha)
- assert.True(t, IsSameDomain(commit))
- assert.False(t, IsSameDomain("http://google.com/ncr"))
- assert.False(t, IsSameDomain("favicon.ico"))
+ assert.True(t, markup.IsSameDomain(commit))
+ assert.False(t, markup.IsSameDomain("http://google.com/ncr"))
+ assert.False(t, markup.IsSameDomain("favicon.ico"))
}
func TestRender_links(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
test := func(input, expected string) {
- buffer, err := RenderString(&RenderContext{
+ buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -147,8 +147,8 @@ func TestRender_links(t *testing.T) {
defaultCustom := setting.Markdown.CustomURLSchemes
setting.Markdown.CustomURLSchemes = []string{"ftp", "magnet"}
- InitializeSanitizer()
- CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes)
+ markup.InitializeSanitizer()
+ markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes)
test(
"https://www.example.com",
@@ -227,18 +227,18 @@ func TestRender_links(t *testing.T) {
// Restore previous settings
setting.Markdown.CustomURLSchemes = defaultCustom
- InitializeSanitizer()
- CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes)
+ markup.InitializeSanitizer()
+ markup.CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes)
}
func TestRender_email(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
test := func(input, expected string) {
- res, err := RenderString(&RenderContext{
+ res, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res))
@@ -289,15 +289,15 @@ func TestRender_email(t *testing.T) {
}
func TestRender_emoji(t *testing.T) {
- setting.AppURL = TestAppURL
- setting.StaticURLPrefix = TestAppURL
+ setting.AppURL = markup.TestAppURL
+ setting.StaticURLPrefix = markup.TestAppURL
test := func(input, expected string) {
expected = strings.ReplaceAll(expected, "&", "&")
- buffer, err := RenderString(&RenderContext{
+ buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -354,19 +354,19 @@ func TestRender_emoji(t *testing.T) {
}
func TestRender_ShortLinks(t *testing.T) {
- setting.AppURL = TestAppURL
- tree := util.URLJoin(TestRepoURL, "src", "master")
+ setting.AppURL = markup.TestAppURL
+ tree := util.URLJoin(markup.TestRepoURL, "src", "master")
test := func(input, expected, expectedWiki string) {
- buffer, err := markdown.RenderString(&RenderContext{
+ buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
URLPrefix: tree,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
- buffer, err = markdown.RenderString(&RenderContext{
+ buffer, err = markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
Metas: localMetas,
IsWiki: true,
}, input)
@@ -374,7 +374,7 @@ func TestRender_ShortLinks(t *testing.T) {
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
}
- rawtree := util.URLJoin(TestRepoURL, "raw", "master")
+ rawtree := util.URLJoin(markup.TestRepoURL, "raw", "master")
url := util.URLJoin(tree, "Link")
otherURL := util.URLJoin(tree, "Other-Link")
encodedURL := util.URLJoin(tree, "Link%3F")
@@ -382,13 +382,13 @@ func TestRender_ShortLinks(t *testing.T) {
otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg")
encodedImgurl := util.URLJoin(rawtree, "Link+%23.jpg")
notencodedImgurl := util.URLJoin(rawtree, "some", "path", "Link+#.jpg")
- urlWiki := util.URLJoin(TestRepoURL, "wiki", "Link")
- otherURLWiki := util.URLJoin(TestRepoURL, "wiki", "Other-Link")
- encodedURLWiki := util.URLJoin(TestRepoURL, "wiki", "Link%3F")
- imgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link.jpg")
- otherImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+Other.jpg")
- encodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "Link+%23.jpg")
- notencodedImgurlWiki := util.URLJoin(TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg")
+ urlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link")
+ otherURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Other-Link")
+ encodedURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link%3F")
+ imgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link.jpg")
+ otherImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+Other.jpg")
+ encodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "Link+%23.jpg")
+ notencodedImgurlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw", "some", "path", "Link+#.jpg")
favicon := "http://google.com/favicon.ico"
test(
@@ -462,20 +462,20 @@ func TestRender_ShortLinks(t *testing.T) {
}
func TestRender_RelativeImages(t *testing.T) {
- setting.AppURL = TestAppURL
- tree := util.URLJoin(TestRepoURL, "src", "master")
+ setting.AppURL = markup.TestAppURL
+ tree := util.URLJoin(markup.TestRepoURL, "src", "master")
test := func(input, expected, expectedWiki string) {
- buffer, err := markdown.RenderString(&RenderContext{
+ buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
URLPrefix: tree,
Metas: localMetas,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
- buffer, err = markdown.RenderString(&RenderContext{
+ buffer, err = markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
- URLPrefix: TestRepoURL,
+ URLPrefix: markup.TestRepoURL,
Metas: localMetas,
IsWiki: true,
}, input)
@@ -483,8 +483,8 @@ func TestRender_RelativeImages(t *testing.T) {
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
}
- rawwiki := util.URLJoin(TestRepoURL, "wiki", "raw")
- mediatree := util.URLJoin(TestRepoURL, "media", "master")
+ rawwiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw")
+ mediatree := util.URLJoin(markup.TestRepoURL, "media", "master")
test(
``,
@@ -498,7 +498,7 @@ func TestRender_RelativeImages(t *testing.T) {
}
func Test_ParseClusterFuzz(t *testing.T) {
- setting.AppURL = TestAppURL
+ setting.AppURL = markup.TestAppURL
localMetas := map[string]string{
"user": "go-gitea",
@@ -508,7 +508,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
data := "