From d8bc0495de03d9232228a9b5aeb6303ceb244537 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 11 Jun 2024 20:47:45 +0200 Subject: [PATCH] Enable `unparam` linter (#31277) Enable [unparam](https://github.com/mvdan/unparam) linter. Often I could not tell the intention why param is unused, so I put `//nolint` for those cases like webhook request creation functions never using `ctx`. --------- Co-authored-by: Lunny Xiao Co-authored-by: delvh (cherry picked from commit fc2d75f86d77b022ece848acf2581c14ef21d43b) Conflicts: modules/setting/config_env.go modules/storage/azureblob.go services/webhook/dingtalk.go services/webhook/discord.go services/webhook/feishu.go services/webhook/matrix.go services/webhook/msteams.go services/webhook/packagist.go services/webhook/slack.go services/webhook/telegram.go services/webhook/wechatwork.go run make lint-go and fix Forgejo specific warnings --- .golangci.yml | 1 + models/dbfs/dbfile.go | 17 ++----- models/issues/issue_search.go | 51 ++++++++----------- models/issues/pull_list.go | 16 ++---- modules/auth/password/hash/common.go | 2 +- modules/git/git.go | 17 +++---- modules/git/object_format.go | 4 +- modules/markup/markdown/transform_codespan.go | 2 +- modules/packages/cran/metadata.go | 18 +++---- modules/setting/config_env.go | 2 +- modules/setting/storage.go | 2 +- modules/util/keypair.go | 9 ++-- routers/api/actions/artifacts.go | 8 +-- routers/api/actions/artifacts_utils.go | 8 +-- routers/api/packages/container/blob.go | 2 +- routers/api/packages/nuget/nuget.go | 2 +- routers/api/v1/repo/compare.go | 2 +- routers/api/v1/repo/pull.go | 28 +++++----- routers/private/hook_pre_receive.go | 4 +- routers/web/admin/config.go | 2 +- routers/web/repo/badges/badges.go | 2 +- services/actions/notifier_helper.go | 2 +- services/f3/driver/repository.go | 2 +- services/f3/driver/tests/options.go | 2 +- services/mailer/mail_admin_new_user.go | 2 +- services/pull/merge.go | 2 +- services/remote/promote.go | 2 +- 27 files changed, 88 insertions(+), 123 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c55a08bba0..57f3c86f05 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,6 +22,7 @@ linters: - typecheck - unconvert - unused + - unparam - wastedassign run: diff --git a/models/dbfs/dbfile.go b/models/dbfs/dbfile.go index 3650ce057e..dd27b5c36b 100644 --- a/models/dbfs/dbfile.go +++ b/models/dbfs/dbfile.go @@ -215,16 +215,15 @@ func fileTimestampToTime(timestamp int64) time.Time { return time.UnixMicro(timestamp) } -func (f *file) loadMetaByPath() (*dbfsMeta, error) { +func (f *file) loadMetaByPath() error { var fileMeta dbfsMeta if ok, err := db.GetEngine(f.ctx).Where("full_path = ?", f.fullPath).Get(&fileMeta); err != nil { - return nil, err + return err } else if ok { f.metaID = fileMeta.ID f.blockSize = fileMeta.BlockSize - return &fileMeta, nil } - return nil, nil + return nil } func (f *file) open(flag int) (err error) { @@ -288,10 +287,7 @@ func (f *file) createEmpty() error { if err != nil { return err } - if _, err = f.loadMetaByPath(); err != nil { - return err - } - return nil + return f.loadMetaByPath() } func (f *file) truncate() error { @@ -368,8 +364,5 @@ func buildPath(path string) string { func newDbFile(ctx context.Context, path string) (*file, error) { path = buildPath(path) f := &file{ctx: ctx, fullPath: path, blockSize: defaultFileBlockSize} - if _, err := f.loadMetaByPath(); err != nil { - return nil, err - } - return f, nil + return f, f.loadMetaByPath() } diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go index 491def1229..c1d7d921a9 100644 --- a/models/issues/issue_search.go +++ b/models/issues/issue_search.go @@ -99,9 +99,9 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) { } } -func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyLimit(sess *xorm.Session, opts *IssuesOptions) { if opts.Paginator == nil || opts.Paginator.IsListAll() { - return sess + return } start := 0 @@ -109,11 +109,9 @@ func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize } sess.Limit(opts.Paginator.PageSize, start) - - return sess } -func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) { if len(opts.LabelIDs) > 0 { if opts.LabelIDs[0] == 0 { sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label)") @@ -136,11 +134,9 @@ func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session if len(opts.ExcludedLabelNames) > 0 { sess.And(builder.NotIn("issue.id", BuildLabelNamesIssueIDsCondition(opts.ExcludedLabelNames))) } - - return sess } -func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) { if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == db.NoConditionID { sess.And("issue.milestone_id = 0") } else if len(opts.MilestoneIDs) > 0 { @@ -153,11 +149,9 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess From("milestone"). Where(builder.In("name", opts.IncludeMilestones))) } - - return sess } -func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) { if opts.ProjectID > 0 { // specific project sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id"). And("project_issue.project_id=?", opts.ProjectID) @@ -166,10 +160,9 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio } // opts.ProjectID == 0 means all projects, // do not need to apply any condition - return sess } -func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) { // opts.ProjectColumnID == 0 means all project columns, // do not need to apply any condition if opts.ProjectColumnID > 0 { @@ -177,10 +170,9 @@ func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) *xorm. } else if opts.ProjectColumnID == db.NoConditionID { sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0})) } - return sess } -func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) { if len(opts.RepoIDs) == 1 { opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]} } else if len(opts.RepoIDs) > 1 { @@ -195,10 +187,9 @@ func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session if opts.RepoCond != nil { sess.And(opts.RepoCond) } - return sess } -func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { +func applyConditions(sess *xorm.Session, opts *IssuesOptions) { if len(opts.IssueIDs) > 0 { sess.In("issue.id", opts.IssueIDs) } @@ -261,8 +252,6 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { if opts.User != nil { sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value())) } - - return sess } // teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access @@ -339,22 +328,22 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati return cond } -func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session { - return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id"). +func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) { + sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id"). And("issue_assignees.assignee_id = ?", assigneeID) } -func applyPosterCondition(sess *xorm.Session, posterID int64) *xorm.Session { - return sess.And("issue.poster_id=?", posterID) +func applyPosterCondition(sess *xorm.Session, posterID int64) { + sess.And("issue.poster_id=?", posterID) } -func applyMentionedCondition(sess *xorm.Session, mentionedID int64) *xorm.Session { - return sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). +func applyMentionedCondition(sess *xorm.Session, mentionedID int64) { + sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). And("issue_user.is_mentioned = ?", true). And("issue_user.uid = ?", mentionedID) } -func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) *xorm.Session { +func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) { existInTeamQuery := builder.Select("team_user.team_id"). From("team_user"). Where(builder.Eq{"team_user.uid": reviewRequestedID}) @@ -375,11 +364,11 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) ), builder.In("review.id", maxReview), )) - return sess.Where("issue.poster_id <> ?", reviewRequestedID). + sess.Where("issue.poster_id <> ?", reviewRequestedID). And(builder.In("issue.id", subQuery)) } -func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session { +func applyReviewedCondition(sess *xorm.Session, reviewedID int64) { // Query for pull requests where you are a reviewer or commenter, excluding // any pull requests already returned by the review requested filter. notPoster := builder.Neq{"issue.poster_id": reviewedID} @@ -406,11 +395,11 @@ func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session builder.In("type", CommentTypeComment, CommentTypeCode, CommentTypeReview), )), ) - return sess.And(notPoster, builder.Or(reviewed, commented)) + sess.And(notPoster, builder.Or(reviewed, commented)) } -func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session { - return sess.And( +func applySubscribedCondition(sess *xorm.Session, subscriberID int64) { + sess.And( builder. NotIn("issue.id", builder.Select("issue_id"). diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go index 52f2f01a5a..9b838df5c3 100644 --- a/models/issues/pull_list.go +++ b/models/issues/pull_list.go @@ -28,7 +28,7 @@ type PullRequestsOptions struct { MilestoneID int64 } -func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) { +func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) *xorm.Session { sess := db.GetEngine(ctx).Where("pull_request.base_repo_id=?", baseRepoID) sess.Join("INNER", "issue", "pull_request.issue_id = issue.id") @@ -46,7 +46,7 @@ func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullR sess.And("issue.milestone_id=?", opts.MilestoneID) } - return sess, nil + return sess } func GetUnmergedPullRequestsByHeadInfoMax(ctx context.Context, repoID, olderThan int64, branch string) ([]*PullRequest, error) { @@ -136,23 +136,15 @@ func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptio opts.Page = 1 } - countSession, err := listPullRequestStatement(ctx, baseRepoID, opts) - if err != nil { - log.Error("listPullRequestStatement: %v", err) - return nil, 0, err - } + countSession := listPullRequestStatement(ctx, baseRepoID, opts) maxResults, err := countSession.Count(new(PullRequest)) if err != nil { log.Error("Count PRs: %v", err) return nil, maxResults, err } - findSession, err := listPullRequestStatement(ctx, baseRepoID, opts) + findSession := listPullRequestStatement(ctx, baseRepoID, opts) applySorts(findSession, opts.SortType, 0) - if err != nil { - log.Error("listPullRequestStatement: %v", err) - return nil, maxResults, err - } findSession = db.SetSessionPagination(findSession, opts) prs := make([]*PullRequest, 0, opts.PageSize) return prs, maxResults, findSession.Find(&prs) diff --git a/modules/auth/password/hash/common.go b/modules/auth/password/hash/common.go index ac6faf35cf..487c0738f4 100644 --- a/modules/auth/password/hash/common.go +++ b/modules/auth/password/hash/common.go @@ -18,7 +18,7 @@ func parseIntParam(value, param, algorithmName, config string, previousErr error return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed } -func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { +func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam parsed, err := strconv.ParseUint(value, 10, 64) if err != nil { log.Error("invalid integer for %s representation in %s hash spec %s", param, algorithmName, config) diff --git a/modules/git/git.go b/modules/git/git.go index d36718d86a..70232c86a0 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -42,20 +42,19 @@ var ( ) // loadGitVersion returns current Git version from shell. Internal usage only. -func loadGitVersion() (*version.Version, error) { +func loadGitVersion() error { // doesn't need RWMutex because it's executed by Init() if gitVersion != nil { - return gitVersion, nil + return nil } - stdout, _, runErr := NewCommand(DefaultContext, "version").RunStdString(nil) if runErr != nil { - return nil, runErr + return runErr } fields := strings.Fields(stdout) if len(fields) < 3 { - return nil, fmt.Errorf("invalid git version output: %s", stdout) + return fmt.Errorf("invalid git version output: %s", stdout) } var versionString string @@ -70,7 +69,7 @@ func loadGitVersion() (*version.Version, error) { var err error gitVersion, err = version.NewVersion(versionString) - return gitVersion, err + return err } // SetExecutablePath changes the path of git executable and checks the file permission and version. @@ -85,7 +84,7 @@ func SetExecutablePath(path string) error { } GitExecutable = absPath - _, err = loadGitVersion() + err = loadGitVersion() if err != nil { return fmt.Errorf("unable to load git version: %w", err) } @@ -312,7 +311,7 @@ func syncGitConfig() (err error) { // CheckGitVersionAtLeast check git version is at least the constraint version func CheckGitVersionAtLeast(atLeast string) error { - if _, err := loadGitVersion(); err != nil { + if err := loadGitVersion(); err != nil { return err } atLeastVersion, err := version.NewVersion(atLeast) @@ -327,7 +326,7 @@ func CheckGitVersionAtLeast(atLeast string) error { // CheckGitVersionEqual checks if the git version is equal to the constraint version. func CheckGitVersionEqual(equal string) error { - if _, err := loadGitVersion(); err != nil { + if err := loadGitVersion(); err != nil { return err } atLeastVersion, err := version.NewVersion(equal) diff --git a/modules/git/object_format.go b/modules/git/object_format.go index 2b462589a3..db9120d827 100644 --- a/modules/git/object_format.go +++ b/modules/git/object_format.go @@ -34,13 +34,13 @@ type ObjectFormat interface { ComputeHash(t ObjectType, content []byte) ObjectID } -func computeHash(dst []byte, hasher hash.Hash, t ObjectType, content []byte) []byte { +func computeHash(dst []byte, hasher hash.Hash, t ObjectType, content []byte) { _, _ = hasher.Write(t.Bytes()) _, _ = hasher.Write([]byte(" ")) _, _ = hasher.Write([]byte(strconv.Itoa(len(content)))) _, _ = hasher.Write([]byte{0}) _, _ = hasher.Write(content) - return hasher.Sum(dst) + hasher.Sum(dst) } /* SHA1 Type */ diff --git a/modules/markup/markdown/transform_codespan.go b/modules/markup/markdown/transform_codespan.go index 0cf1169dee..a2cd4fb5ba 100644 --- a/modules/markup/markdown/transform_codespan.go +++ b/modules/markup/markdown/transform_codespan.go @@ -48,7 +48,7 @@ func (r *HTMLRenderer) renderCodeSpan(w util.BufWriter, source []byte, n ast.Nod return ast.WalkContinue, nil } -func (g *ASTTransformer) transformCodeSpan(ctx *markup.RenderContext, v *ast.CodeSpan, reader text.Reader) { +func (g *ASTTransformer) transformCodeSpan(_ *markup.RenderContext, v *ast.CodeSpan, reader text.Reader) { colorContent := v.Text(reader.Source()) if matchColor(strings.ToLower(string(colorContent))) { v.AppendChild(v, NewColorPreview(colorContent)) diff --git a/modules/packages/cran/metadata.go b/modules/packages/cran/metadata.go index 24e6f323af..0b0bfb07c6 100644 --- a/modules/packages/cran/metadata.go +++ b/modules/packages/cran/metadata.go @@ -185,8 +185,6 @@ func ParseDescription(r io.Reader) (*Package, error) { } func setField(p *Package, data string) error { - const listDelimiter = ", " - if data == "" { return nil } @@ -215,19 +213,19 @@ func setField(p *Package, data string) error { case "Description": p.Metadata.Description = value case "URL": - p.Metadata.ProjectURL = splitAndTrim(value, listDelimiter) + p.Metadata.ProjectURL = splitAndTrim(value) case "License": p.Metadata.License = value case "Author": - p.Metadata.Authors = splitAndTrim(authorReplacePattern.ReplaceAllString(value, ""), listDelimiter) + p.Metadata.Authors = splitAndTrim(authorReplacePattern.ReplaceAllString(value, "")) case "Depends": - p.Metadata.Depends = splitAndTrim(value, listDelimiter) + p.Metadata.Depends = splitAndTrim(value) case "Imports": - p.Metadata.Imports = splitAndTrim(value, listDelimiter) + p.Metadata.Imports = splitAndTrim(value) case "Suggests": - p.Metadata.Suggests = splitAndTrim(value, listDelimiter) + p.Metadata.Suggests = splitAndTrim(value) case "LinkingTo": - p.Metadata.LinkingTo = splitAndTrim(value, listDelimiter) + p.Metadata.LinkingTo = splitAndTrim(value) case "NeedsCompilation": p.Metadata.NeedsCompilation = value == "yes" } @@ -235,8 +233,8 @@ func setField(p *Package, data string) error { return nil } -func splitAndTrim(s, sep string) []string { - items := strings.Split(s, sep) +func splitAndTrim(s string) []string { + items := strings.Split(s, ", ") for i := range items { items[i] = strings.TrimSpace(items[i]) } diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go index 522e360303..fa0100dba2 100644 --- a/modules/setting/config_env.go +++ b/modules/setting/config_env.go @@ -97,7 +97,7 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) { // decodeEnvironmentKey decode the environment key to section and key // The environment key is in the form of GITEA__SECTION__KEY or GITEA__SECTION__KEY__FILE -func decodeEnvironmentKey(prefixRegexp *regexp.Regexp, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) { +func decodeEnvironmentKey(prefixRegexp *regexp.Regexp, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) { //nolint:unparam if strings.HasSuffix(envKey, suffixFile) { useFileValue = true envKey = envKey[:len(envKey)-len(suffixFile)] diff --git a/modules/setting/storage.go b/modules/setting/storage.go index c082579d39..8ee5c0f0ab 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -122,7 +122,7 @@ const ( targetSecIsSec // target section is from the name seciont [name] ) -func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) { +func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) { //nolint:unparam targetSec, err := rootCfg.GetSection(storageSectionName + "." + typ) if err != nil { if !IsValidStorageType(StorageType(typ)) { diff --git a/modules/util/keypair.go b/modules/util/keypair.go index 8b86c142af..07f27bd1ba 100644 --- a/modules/util/keypair.go +++ b/modules/util/keypair.go @@ -15,10 +15,7 @@ import ( // GenerateKeyPair generates a public and private keypair func GenerateKeyPair(bits int) (string, string, error) { priv, _ := rsa.GenerateKey(rand.Reader, bits) - privPem, err := pemBlockForPriv(priv) - if err != nil { - return "", "", err - } + privPem := pemBlockForPriv(priv) pubPem, err := pemBlockForPub(&priv.PublicKey) if err != nil { return "", "", err @@ -26,12 +23,12 @@ func GenerateKeyPair(bits int) (string, string, error) { return privPem, pubPem, nil } -func pemBlockForPriv(priv *rsa.PrivateKey) (string, error) { +func pemBlockForPriv(priv *rsa.PrivateKey) string { privBytes := pem.EncodeToMemory(&pem.Block{ Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv), }) - return string(privBytes), nil + return string(privBytes) } func pemBlockForPub(pub *rsa.PublicKey) (string, error) { diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go index 7225d67135..6aa0ecaaec 100644 --- a/routers/api/actions/artifacts.go +++ b/routers/api/actions/artifacts.go @@ -241,16 +241,12 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) { } // get upload file size - fileRealTotalSize, contentLength, err := getUploadFileSize(ctx) - if err != nil { - log.Error("Error get upload file size: %v", err) - ctx.Error(http.StatusInternalServerError, "Error get upload file size") - return - } + fileRealTotalSize, contentLength := getUploadFileSize(ctx) // get artifact retention days expiredDays := setting.Actions.ArtifactRetentionDays if queryRetentionDays := ctx.Req.URL.Query().Get("retentionDays"); queryRetentionDays != "" { + var err error expiredDays, err = strconv.ParseInt(queryRetentionDays, 10, 64) if err != nil { log.Error("Error parse retention days: %v", err) diff --git a/routers/api/actions/artifacts_utils.go b/routers/api/actions/artifacts_utils.go index d2e7ccaea1..db602f1e14 100644 --- a/routers/api/actions/artifacts_utils.go +++ b/routers/api/actions/artifacts_utils.go @@ -43,7 +43,7 @@ func validateRunID(ctx *ArtifactContext) (*actions.ActionTask, int64, bool) { return task, runID, true } -func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) { +func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) { //nolint:unparam task := ctx.ActionTask runID, err := strconv.ParseInt(rawRunID, 10, 64) if err != nil || task.Job.RunID != runID { @@ -84,11 +84,11 @@ func parseArtifactItemPath(ctx *ArtifactContext) (string, string, bool) { // getUploadFileSize returns the size of the file to be uploaded. // The raw size is the size of the file as reported by the header X-TFS-FileLength. -func getUploadFileSize(ctx *ArtifactContext) (int64, int64, error) { +func getUploadFileSize(ctx *ArtifactContext) (int64, int64) { contentLength := ctx.Req.ContentLength xTfsLength, _ := strconv.ParseInt(ctx.Req.Header.Get(artifactXTfsFileLengthHeader), 10, 64) if xTfsLength > 0 { - return xTfsLength, contentLength, nil + return xTfsLength, contentLength } - return contentLength, contentLength, nil + return contentLength, contentLength } diff --git a/routers/api/packages/container/blob.go b/routers/api/packages/container/blob.go index f2d63297c1..9e3a47076c 100644 --- a/routers/api/packages/container/blob.go +++ b/routers/api/packages/container/blob.go @@ -26,7 +26,7 @@ var uploadVersionMutex sync.Mutex // saveAsPackageBlob creates a package blob from an upload // The uploaded blob gets stored in a special upload version to link them to the package/image -func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { +func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { //nolint:unparam pb := packages_service.NewPackageBlob(hsr) exists := false diff --git a/routers/api/packages/nuget/nuget.go b/routers/api/packages/nuget/nuget.go index 3633d0d007..0d7212d7f7 100644 --- a/routers/api/packages/nuget/nuget.go +++ b/routers/api/packages/nuget/nuget.go @@ -36,7 +36,7 @@ func apiError(ctx *context.Context, status int, obj any) { }) } -func xmlResponse(ctx *context.Context, status int, obj any) { +func xmlResponse(ctx *context.Context, status int, obj any) { //nolint:unparam ctx.Resp.Header().Set("Content-Type", "application/atom+xml; charset=utf-8") ctx.Resp.WriteHeader(status) if _, err := ctx.Resp.Write([]byte(xml.Header)); err != nil { diff --git a/routers/api/v1/repo/compare.go b/routers/api/v1/repo/compare.go index cfd61d768c..429145c714 100644 --- a/routers/api/v1/repo/compare.go +++ b/routers/api/v1/repo/compare.go @@ -64,7 +64,7 @@ func CompareDiff(ctx *context.APIContext) { } } - _, _, headGitRepo, ci, _, _ := parseCompareInfo(ctx, api.CreatePullRequestOption{ + _, headGitRepo, ci, _, _ := parseCompareInfo(ctx, api.CreatePullRequestOption{ Base: infos[0], Head: infos[1], }) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index b8314d6eb0..725a33929f 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -406,7 +406,7 @@ func CreatePullRequest(ctx *context.APIContext) { ) // Get repo/branch information - _, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form) + headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form) if ctx.Written() { return } @@ -1051,7 +1051,7 @@ func MergePullRequest(ctx *context.APIContext) { ctx.Status(http.StatusOK) } -func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *repo_model.Repository, *git.Repository, *git.CompareInfo, string, string) { +func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*repo_model.Repository, *git.Repository, *git.CompareInfo, string, string) { baseRepo := ctx.Repo.Repository // Get compared branches information @@ -1084,14 +1084,14 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } else { ctx.Error(http.StatusInternalServerError, "GetUserByName", err) } - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } headBranch = headInfos[1] // The head repository can also point to the same repo isSameRepo = ctx.Repo.Owner.ID == headUser.ID } else { ctx.NotFound() - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } ctx.Repo.PullRequest.SameRepo = isSameRepo @@ -1099,7 +1099,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if base branch is valid. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) { ctx.NotFound("BaseNotExist") - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } // Check if current user has fork of repository or in the same repository. @@ -1107,7 +1107,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if headRepo == nil && !isSameRepo { log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) ctx.NotFound("GetForkedRepo") - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } var headGitRepo *git.Repository @@ -1118,7 +1118,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo) if err != nil { ctx.Error(http.StatusInternalServerError, "OpenRepository", err) - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } } @@ -1127,7 +1127,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if err != nil { headGitRepo.Close() ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) { if log.IsTrace() { @@ -1138,7 +1138,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } headGitRepo.Close() ctx.NotFound("Can't read pulls or can't read UnitTypeCode") - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } // user should have permission to read headrepo's codes @@ -1146,7 +1146,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if err != nil { headGitRepo.Close() ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } if !permHead.CanRead(unit.TypeCode) { if log.IsTrace() { @@ -1157,24 +1157,24 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } headGitRepo.Close() ctx.NotFound("Can't read headRepo UnitTypeCode") - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } // Check if head branch is valid. if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) { headGitRepo.Close() ctx.NotFound() - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch, false, false) if err != nil { headGitRepo.Close() ctx.Error(http.StatusInternalServerError, "GetCompareInfo", err) - return nil, nil, nil, nil, "", "" + return nil, nil, nil, "", "" } - return headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch + return headRepo, headGitRepo, compareInfo, baseBranch, headBranch } // UpdatePullRequest merge PR's baseBranch into headBranch diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index d12a762db6..456a288b00 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -434,7 +434,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r } } -func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID string, refFullName git.RefName) { +func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID string, refFullName git.RefName) { //nolint:unparam if !ctx.AssertCanWriteCode() { return } @@ -470,7 +470,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID string, refF } } -func preReceiveFor(ctx *preReceiveContext, oldCommitID, newCommitID string, refFullName git.RefName) { +func preReceiveFor(ctx *preReceiveContext, oldCommitID, newCommitID string, refFullName git.RefName) { //nolint:unparam if !ctx.AssertCreatePullRequest() { return } diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 2f5f17e201..22f260eded 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -183,7 +183,7 @@ func ChangeConfig(ctx *context.Context) { value := ctx.FormString("value") cfg := setting.Config() - marshalBool := func(v string) (string, error) { + marshalBool := func(v string) (string, error) { //nolint:unparam if b, _ := strconv.ParseBool(v); b { return "true", nil } diff --git a/routers/web/repo/badges/badges.go b/routers/web/repo/badges/badges.go index f240d30a31..a2306d5836 100644 --- a/routers/web/repo/badges/badges.go +++ b/routers/web/repo/badges/badges.go @@ -39,7 +39,7 @@ func redirectToBadge(ctx *context_module.Context, label, text, color string) { ctx.Redirect(getBadgeURL(ctx, label, text, color)) } -func errorBadge(ctx *context_module.Context, label, text string) { +func errorBadge(ctx *context_module.Context, label, text string) { //nolint:unparam ctx.Redirect(getBadgeURL(ctx, label, text, "crimson")) } diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 78f413c214..4196cf7686 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -474,7 +474,7 @@ func handleSchedules( detectedWorkflows []*actions_module.DetectedWorkflow, commit *git.Commit, input *notifyInput, - ref string, + _ string, ) error { branch, err := commit.GetBranchName() if err != nil { diff --git a/services/f3/driver/repository.go b/services/f3/driver/repository.go index 73e81a39b1..203622ad9b 100644 --- a/services/f3/driver/repository.go +++ b/services/f3/driver/repository.go @@ -92,7 +92,7 @@ func (o *repository) GetRepositoryPushURL() string { return o.getURL() } -func newRepository(ctx context.Context) generic.NodeDriverInterface { +func newRepository(_ context.Context) generic.NodeDriverInterface { r := &repository{ f: &f3.Repository{}, } diff --git a/services/f3/driver/tests/options.go b/services/f3/driver/tests/options.go index f115fd80f6..adaa1da588 100644 --- a/services/f3/driver/tests/options.go +++ b/services/f3/driver/tests/options.go @@ -14,7 +14,7 @@ import ( "code.forgejo.org/f3/gof3/v3/options" ) -func newTestOptions(t *testing.T) options.Interface { +func newTestOptions(_ *testing.T) options.Interface { o := options.GetFactory(driver_options.Name)().(*driver_options.Options) o.SetLogger(util.NewF3Logger(nil, forgejo_log.GetLogger(forgejo_log.DEFAULT))) return o diff --git a/services/mailer/mail_admin_new_user.go b/services/mailer/mail_admin_new_user.go index 54287b1b7e..0713de8a95 100644 --- a/services/mailer/mail_admin_new_user.go +++ b/services/mailer/mail_admin_new_user.go @@ -45,7 +45,7 @@ func MailNewUser(ctx context.Context, u *user_model.User) { } } -func mailNewUser(ctx context.Context, u *user_model.User, lang string, tos []string) { +func mailNewUser(_ context.Context, u *user_model.User, lang string, tos []string) { locale := translation.NewLocale(lang) manageUserURL := setting.AppURL + "admin/users/" + strconv.FormatInt(u.ID, 10) diff --git a/services/pull/merge.go b/services/pull/merge.go index 0d37daa6ed..75b22e00b3 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -252,7 +252,7 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U } // doMergeAndPush performs the merge operation without changing any pull information in database and pushes it up to the base repository -func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, pushTrigger repo_module.PushTrigger) (string, error) { +func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, pushTrigger repo_module.PushTrigger) (string, error) { //nolint:unparam // Clone base repo. mergeCtx, cancel, err := createTemporaryRepoForMerge(ctx, pr, doer, expectedHeadCommitID) if err != nil { diff --git a/services/remote/promote.go b/services/remote/promote.go index 5402c946d7..eb41ace462 100644 --- a/services/remote/promote.go +++ b/services/remote/promote.go @@ -84,7 +84,7 @@ func MaybePromoteRemoteUser(ctx context.Context, source *auth_model.Source, logi return true, reason, nil } -func getRemoteUserToPromote(ctx context.Context, source *auth_model.Source, loginName, email string) (*user_model.User, Reason, error) { +func getRemoteUserToPromote(ctx context.Context, source *auth_model.Source, loginName, email string) (*user_model.User, Reason, error) { //nolint:unparam if !source.IsOAuth2() { return nil, NewReason(log.DEBUG, ReasonNotAuth2, "source %v is not OAuth2", source), nil }