Skip to content

Commit b5ecae5

Browse files
42wimSysoev, Vladimir
authored andcommitted
Add more linters to improve code readability (go-gitea#19989)
Add nakedret, unconvert, wastedassign, stylecheck and nolintlint linters to improve code readability - nakedret - https://github.com/alexkohler/nakedret - nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length. - unconvert - https://github.com/mdempsky/unconvert - Remove unnecessary type conversions - wastedassign - https://github.com/sanposhiho/wastedassign - wastedassign finds wasted assignment statements. - notlintlint - Reports ill-formed or insufficient nolint directives - stylecheck - https://staticcheck.io/docs/checks/#ST - keep style consistent - excluded: [ST1003 - Poorly chosen identifier](https://staticcheck.io/docs/checks/#ST1003) and [ST1005 - Incorrectly formatted error string](https://staticcheck.io/docs/checks/#ST1005)
1 parent 505d552 commit b5ecae5

File tree

147 files changed

+402
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+402
-397
lines changed

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ linters:
1919
- revive
2020
- gofumpt
2121
- depguard
22+
- nakedret
23+
- unconvert
24+
- wastedassign
25+
- nolintlint
26+
- stylecheck
2227
enable-all: false
2328
disable-all: true
2429
fast: false
@@ -32,6 +37,10 @@ run:
3237
- web_src
3338

3439
linters-settings:
40+
stylecheck:
41+
checks: ["all", "-ST1005", "-ST1003"]
42+
nakedret:
43+
max-func-lines: 0
3544
gocritic:
3645
disabled-checks:
3746
- ifElseChain

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func writeDataPktLine(out io.Writer, data []byte) error {
792792
if err != nil {
793793
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
794794
}
795-
if 4 != lr {
795+
if lr != 4 {
796796
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
797797
}
798798

integrations/api_issue_stopwatch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAPIListStopWatches(t *testing.T) {
3838
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
3939
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
4040
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
41-
assert.Greater(t, int64(apiWatches[0].Seconds), int64(0))
41+
assert.Greater(t, apiWatches[0].Seconds, int64(0))
4242
}
4343
}
4444

integrations/api_packages_container_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestPackageContainer(t *testing.T) {
8888

8989
req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
9090
addTokenAuthHeader(req, anonymousToken)
91-
resp = MakeRequest(t, req, http.StatusOK)
91+
MakeRequest(t, req, http.StatusOK)
9292
})
9393

9494
t.Run("User", func(t *testing.T) {
@@ -112,7 +112,7 @@ func TestPackageContainer(t *testing.T) {
112112

113113
req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
114114
addTokenAuthHeader(req, userToken)
115-
resp = MakeRequest(t, req, http.StatusOK)
115+
MakeRequest(t, req, http.StatusOK)
116116
})
117117
})
118118

integrations/editor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
8282
"_csrf": csrf,
8383
"protected": "off",
8484
})
85-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
85+
session.MakeRequest(t, req, http.StatusSeeOther)
8686
// Check if master branch has been locked successfully
8787
flashCookie = session.GetCookie("macaron_flash")
8888
assert.NotNil(t, flashCookie)
@@ -109,7 +109,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
109109
"commit_choice": "direct",
110110
},
111111
)
112-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
112+
session.MakeRequest(t, req, http.StatusSeeOther)
113113

114114
// Verify the change
115115
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath))
@@ -139,7 +139,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
139139
"new_branch_name": targetBranch,
140140
},
141141
)
142-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
142+
session.MakeRequest(t, req, http.StatusSeeOther)
143143

144144
// Verify the change
145145
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath))

integrations/git_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string
150150
defer PrintCurrentTest(t)()
151151
little, big = commitAndPushTest(t, dstPath, "data-file-")
152152
})
153-
return
153+
return little, big
154154
}
155155

156156
func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS string) {
@@ -191,7 +191,7 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
191191
lockTest(t, dstPath)
192192
})
193193
})
194-
return
194+
return littleLFS, bigLFS
195195
}
196196

197197
func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string) {
@@ -210,7 +210,7 @@ func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string
210210
big = doCommitAndPush(t, bigSize, dstPath, prefix)
211211
})
212212
})
213-
return
213+
return little, big
214214
}
215215

216216
func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) {

integrations/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
438438
"_csrf": doc.GetCSRF(),
439439
"name": fmt.Sprintf("api-testing-token-%d", tokenCounter),
440440
})
441-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
441+
session.MakeRequest(t, req, http.StatusSeeOther)
442442
req = NewRequest(t, "GET", "/user/settings/applications")
443443
resp = session.MakeRequest(t, req, http.StatusOK)
444444
htmlDoc := NewHTMLParser(t, resp.Body)

integrations/nonascii_branches_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route,
2626

2727
// Perform redirect
2828
req = NewRequest(t, "GET", location)
29-
resp = session.MakeRequest(t, req, expectedStatus)
29+
session.MakeRequest(t, req, expectedStatus)
3030
}
3131

3232
func setDefaultBranch(t *testing.T, session *TestSession, user, repo, branch string) {

integrations/oauth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
197197
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally
198198
})
199199
req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OmJsYWJsYQ==")
200-
resp = MakeRequest(t, req, http.StatusBadRequest)
200+
MakeRequest(t, req, http.StatusBadRequest)
201201

202202
// missing header
203203
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
@@ -206,7 +206,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
206206
"code": "authcode",
207207
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally
208208
})
209-
resp = MakeRequest(t, req, http.StatusBadRequest)
209+
MakeRequest(t, req, http.StatusBadRequest)
210210
}
211211

212212
func TestRefreshTokenInvalidation(t *testing.T) {

integrations/repo_fork_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO
4545
"uid": fmt.Sprintf("%d", forkOwner.ID),
4646
"repo_name": forkRepoName,
4747
})
48-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
48+
session.MakeRequest(t, req, http.StatusSeeOther)
4949

5050
// Step4: check the existence of the forked repo
5151
req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)

0 commit comments

Comments
 (0)