diff options
author | Wim <wim@42.be> | 2022-06-20 12:02:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-20 12:02:49 +0200 |
commit | cb50375e2b6abf0c79d4891e5e1ea775b9759cd2 (patch) | |
tree | 938af0f442baf79cebd114692aff5ad6af37f987 /routers/api/v1 | |
parent | 3289abcefc563d6ea16c1dbd19680b874a58a6d3 (diff) | |
download | gitea-cb50375e2b6abf0c79d4891e5e1ea775b9759cd2.tar.gz gitea-cb50375e2b6abf0c79d4891e5e1ea775b9759cd2.zip |
Add more linters to improve code readability (#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)
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/activitypub/reqsignature.go | 6 | ||||
-rw-r--r-- | routers/api/v1/notify/notifications.go | 2 | ||||
-rw-r--r-- | routers/api/v1/org/org.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/file.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_label.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/status.go | 2 | ||||
-rw-r--r-- | routers/api/v1/utils/hook.go | 2 |
7 files changed, 9 insertions, 9 deletions
diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index b870d1c0f9..5c0776602b 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -41,7 +41,7 @@ func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err return } p, err = x509.ParsePKIXPublicKey(block.Bytes) - return + return p, err } func fetch(iri *url.URL) (b []byte, err error) { @@ -59,7 +59,7 @@ func fetch(iri *url.URL) (b []byte, err error) { return } b, err = io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize)) - return + return b, err } func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, err error) { @@ -87,7 +87,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) authenticated = v.Verify(pubKey, algo) == nil - return + return authenticated, err } // ReqHTTPSignature function diff --git a/routers/api/v1/notify/notifications.go b/routers/api/v1/notify/notifications.go index 0a3684fbe6..44cb4ae769 100644 --- a/routers/api/v1/notify/notifications.go +++ b/routers/api/v1/notify/notifications.go @@ -63,5 +63,5 @@ func subjectToSource(value []string) (result []models.NotificationSource) { result = append(result, models.NotificationSourceRepository) } } - return + return result } diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index d55a4a4514..5a8b253a20 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -47,7 +47,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) { } ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) - ctx.SetTotalCountHeader(int64(maxResults)) + ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &apiOrgs) } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 2190094bac..1ac1088839 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -251,7 +251,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, lastModified time } blob = entry.Blob() - return + return blob, lastModified } // GetArchive get archive of a repository diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index 50c09e02fa..091f1ce27c 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -321,5 +321,5 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) return } - return + return issue, labels, err } diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index f7bc2c5c88..10e78f2a9b 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -57,7 +57,7 @@ func NewCommitStatus(ctx *context.APIContext) { return } status := &git_model.CommitStatus{ - State: api.CommitStatusState(form.State), + State: form.State, TargetURL: form.TargetURL, Description: form.Description, Context: form.Context, diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 4c3753231d..f0dc595ad5 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -133,7 +133,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID BranchFilter: form.BranchFilter, }, IsActive: form.Active, - Type: webhook.HookType(form.Type), + Type: form.Type, } if w.Type == webhook.SLACK { channel, ok := form.Config["channel"] |