mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-25 06:03:40 +09:00
refactor: fix go vet errors related to composite literals (#39341)
Fix these `go vet` errors which I stumbled upon because AI likes to run `go vet` standalone and `go vet` does not understand `//nolint` like golangci does, so it produced confusing output. Co-authored-by: bircni <bircni@icloud.com>
This commit is contained in:
@@ -10,6 +10,7 @@ linters:
|
||||
- depguard
|
||||
- dupl
|
||||
- errcheck
|
||||
- exhaustruct_v5
|
||||
- forbidigo
|
||||
- forcetypeassert
|
||||
- gocheckcompilerdirectives
|
||||
@@ -133,6 +134,8 @@ linters:
|
||||
enable:
|
||||
- nilness
|
||||
- unusedwrite
|
||||
exhaustruct_v5:
|
||||
explicit-mode: true
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
|
||||
@@ -45,7 +45,7 @@ func (j jsonProvider) NewEncoder(writer io.Writer) binding.JSONEncoder {
|
||||
}
|
||||
|
||||
func newFieldError(field reflect.StructField, cls, msg string) *BindingError {
|
||||
return &BindingError{[]string{field.Name}, cls, msg} //nolint:govet // make sure no missing fields
|
||||
return &BindingError{FieldNames: []string{field.Name}, Classification: cls, Message: msg}
|
||||
}
|
||||
|
||||
func AddValidationError(errs BindingErrors, fieldName, errorMsg string) BindingErrors {
|
||||
@@ -159,5 +159,5 @@ var Binder = sync.OnceValue(func() *binding.Binder {
|
||||
|
||||
type (
|
||||
BindingErrors = binding.Errors
|
||||
BindingError = binding.Error
|
||||
BindingError = binding.Error //exhaustruct:enforce
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//nolint:govet // disable "composites: gitea.dev/modules/git.FastImportFile struct literal uses unkeyed fields"
|
||||
package integration
|
||||
|
||||
import (
|
||||
@@ -307,27 +306,27 @@ func testViewRepoDirectoryReadme(t *testing.T) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"})
|
||||
repo56 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user2.ID, Name: "readme-test"})
|
||||
|
||||
const regular, symlink = git.EntryModeBlob, git.EntryModeSymlink
|
||||
const symlink = git.EntryModeSymlink
|
||||
|
||||
allGitea := []git.FastImportFile{
|
||||
{regular, ".gitea/README.en.md", "This is .gitea/README.en.md"},
|
||||
{regular, ".gitea/README.md", "This is .gitea/README.md"},
|
||||
{regular, ".gitea/README", "This is .gitea/README"},
|
||||
{Path: ".gitea/README.en.md", Content: "This is .gitea/README.en.md"},
|
||||
{Path: ".gitea/README.md", Content: "This is .gitea/README.md"},
|
||||
{Path: ".gitea/README", Content: "This is .gitea/README"},
|
||||
}
|
||||
allGithub := []git.FastImportFile{
|
||||
{regular, ".github/README.en.md", "This is .github/README.en.md"},
|
||||
{regular, ".github/README.md", "This is .github/README.md"},
|
||||
{regular, ".github/README", "This is .github/README"},
|
||||
{Path: ".github/README.en.md", Content: "This is .github/README.en.md"},
|
||||
{Path: ".github/README.md", Content: "This is .github/README.md"},
|
||||
{Path: ".github/README", Content: "This is .github/README"},
|
||||
}
|
||||
allRoot := []git.FastImportFile{
|
||||
{regular, "README.en.md", "This is README.en.md"},
|
||||
{regular, "README.md", "This is README.md"},
|
||||
{regular, "README", "This is README"},
|
||||
{Path: "README.en.md", Content: "This is README.en.md"},
|
||||
{Path: "README.md", Content: "This is README.md"},
|
||||
{Path: "README", Content: "This is README"},
|
||||
}
|
||||
allDocs := []git.FastImportFile{
|
||||
{regular, "docs/README.en.md", "This is docs/README.en.md"},
|
||||
{regular, "docs/README.md", "This is docs/README.md"},
|
||||
{regular, "docs/README", "This is docs/README"},
|
||||
{Path: "docs/README.en.md", Content: "This is docs/README.en.md"},
|
||||
{Path: "docs/README.md", Content: "This is docs/README.md"},
|
||||
{Path: "docs/README", Content: "This is docs/README"},
|
||||
}
|
||||
|
||||
combineFiles := func(slices ...[]git.FastImportFile) (res []git.FastImportFile) {
|
||||
@@ -338,33 +337,33 @@ func testViewRepoDirectoryReadme(t *testing.T) {
|
||||
}
|
||||
|
||||
err := git.ForceFastImport(t.Context(), repo56.CodeStorageRepo(), []git.FastImportCommit{
|
||||
{Ref: "refs/heads/master", Message: "init master", Files: []git.FastImportFile{{regular, "README.md", "The cake is a lie."}}},
|
||||
{Ref: "refs/heads/txt", Message: "init txt", Files: []git.FastImportFile{{regular, "README.txt", "My spoon is too big."}}},
|
||||
{Ref: "refs/heads/plain", Message: "init plain", Files: []git.FastImportFile{{regular, "README", "Birken my stocks gee howdy"}}},
|
||||
{Ref: "refs/heads/i18n", Message: "init i18n", Files: []git.FastImportFile{{regular, "README.zh.md", "你好世界"}}},
|
||||
{Ref: "refs/heads/subdir", Message: "init subdir", Files: []git.FastImportFile{{regular, "libcake/README.md", "Four pints of sugar."}}},
|
||||
{Ref: "refs/heads/special-subdir-docs", Message: "init special-subdir-docs", Files: []git.FastImportFile{{regular, "docs/README.md", "This is in docs/"}}},
|
||||
{Ref: "refs/heads/special-subdir-.gitea", Message: "init special-subdir-.gitea", Files: []git.FastImportFile{{regular, ".gitea/README.md", "This is in .gitea/"}}},
|
||||
{Ref: "refs/heads/special-subdir-.github", Message: "init special-subdir-.github", Files: []git.FastImportFile{{regular, ".github/README.md", "This is in .github/"}}},
|
||||
{Ref: "refs/heads/master", Message: "init master", Files: []git.FastImportFile{{Path: "README.md", Content: "The cake is a lie."}}},
|
||||
{Ref: "refs/heads/txt", Message: "init txt", Files: []git.FastImportFile{{Path: "README.txt", Content: "My spoon is too big."}}},
|
||||
{Ref: "refs/heads/plain", Message: "init plain", Files: []git.FastImportFile{{Path: "README", Content: "Birken my stocks gee howdy"}}},
|
||||
{Ref: "refs/heads/i18n", Message: "init i18n", Files: []git.FastImportFile{{Path: "README.zh.md", Content: "你好世界"}}},
|
||||
{Ref: "refs/heads/subdir", Message: "init subdir", Files: []git.FastImportFile{{Path: "libcake/README.md", Content: "Four pints of sugar."}}},
|
||||
{Ref: "refs/heads/special-subdir-docs", Message: "init special-subdir-docs", Files: []git.FastImportFile{{Path: "docs/README.md", Content: "This is in docs/"}}},
|
||||
{Ref: "refs/heads/special-subdir-.gitea", Message: "init special-subdir-.gitea", Files: []git.FastImportFile{{Path: ".gitea/README.md", Content: "This is in .gitea/"}}},
|
||||
{Ref: "refs/heads/special-subdir-.github", Message: "init special-subdir-.github", Files: []git.FastImportFile{{Path: ".github/README.md", Content: "This is in .github/"}}},
|
||||
{Ref: "refs/heads/special-subdir-nested", Message: "init special-subdir-nested", Files: []git.FastImportFile{
|
||||
{regular, ".gitea/docs/README.md", "This is in docs/"},
|
||||
{regular, "subproject/.github/README.md", "This is in .github/"},
|
||||
{Path: ".gitea/docs/README.md", Content: "This is in docs/"},
|
||||
{Path: "subproject/.github/README.md", Content: "This is in .github/"},
|
||||
}},
|
||||
{Ref: "refs/heads/symlink", Message: "init symlink", Files: []git.FastImportFile{
|
||||
{symlink, ".github/README.md", "../some/other/path/awefulcake.txt"},
|
||||
{symlink, "some/README.txt", "other/path/awefulcake.txt"},
|
||||
{regular, "some/other/path/awefulcake.txt", "This is in some/other/path"},
|
||||
{symlink, "trampoline", "up/back/down/down"},
|
||||
{symlink, "up/back/down/down/README.md", "../../../../up/down/left/reelmein"},
|
||||
{regular, "up/down/left/reelmein", "It's a me, mario"},
|
||||
{Mode: symlink, Path: ".github/README.md", Content: "../some/other/path/awefulcake.txt"},
|
||||
{Mode: symlink, Path: "some/README.txt", Content: "other/path/awefulcake.txt"},
|
||||
{Path: "some/other/path/awefulcake.txt", Content: "This is in some/other/path"},
|
||||
{Mode: symlink, Path: "trampoline", Content: "up/back/down/down"},
|
||||
{Mode: symlink, Path: "up/back/down/down/README.md", Content: "../../../../up/down/left/reelmein"},
|
||||
{Path: "up/down/left/reelmein", Content: "It's a me, mario"},
|
||||
}},
|
||||
{Ref: "refs/heads/symlink-loop", Message: "init symlink-loop", Files: []git.FastImportFile{
|
||||
{symlink, "README.md", "trampoline"},
|
||||
{symlink, "some/README.txt", "other/path/awefulcake.txt"},
|
||||
{symlink, "some/other/path/awefulcake.txt", "../../../README.md"},
|
||||
{symlink, "trampoline", "README.md"},
|
||||
{Mode: symlink, Path: "README.md", Content: "trampoline"},
|
||||
{Mode: symlink, Path: "some/README.txt", Content: "other/path/awefulcake.txt"},
|
||||
{Mode: symlink, Path: "some/other/path/awefulcake.txt", Content: "../../../README.md"},
|
||||
{Mode: symlink, Path: "trampoline", Content: "README.md"},
|
||||
}},
|
||||
{Ref: "refs/heads/sp-ace", Message: "init sp-ace", Files: []git.FastImportFile{{regular, "read me", "The cake is a lie."}}},
|
||||
{Ref: "refs/heads/sp-ace", Message: "init sp-ace", Files: []git.FastImportFile{{Path: "read me", Content: "The cake is a lie."}}},
|
||||
{Ref: "refs/heads/fallbacks", Message: "init fallbacks", Files: combineFiles(allGitea, allGithub, allRoot, allDocs)},
|
||||
{Ref: "refs/heads/fallbacks2", Message: "init fallbacks2", Files: combineFiles(allGitea[1:], allGithub, allRoot, allDocs)},
|
||||
{Ref: "refs/heads/fallbacks3", Message: "init fallbacks3", Files: combineFiles(allGitea[2:], allGithub, allRoot, allDocs)},
|
||||
@@ -378,10 +377,10 @@ func testViewRepoDirectoryReadme(t *testing.T) {
|
||||
{Ref: "refs/heads/fallbacks11", Message: "init fallbacks11", Files: combineFiles(allDocs[1:])},
|
||||
{Ref: "refs/heads/fallbacks12", Message: "init fallbacks12", Files: combineFiles(allDocs[2:])},
|
||||
{Ref: "refs/heads/fallbacks-broken-symlinks", Message: "init fallbacks-broken-symlinks", Files: []git.FastImportFile{
|
||||
{symlink, ".gitea/README.md", "non-existent-file"},
|
||||
{symlink, ".github/README.md", "non-existent-file"},
|
||||
{symlink, "README.md", "non-existent-file"},
|
||||
{regular, "docs/README", "This is docs/README"},
|
||||
{Mode: symlink, Path: ".gitea/README.md", Content: "non-existent-file"},
|
||||
{Mode: symlink, Path: ".github/README.md", Content: "non-existent-file"},
|
||||
{Mode: symlink, Path: "README.md", Content: "non-existent-file"},
|
||||
{Path: "docs/README", Content: "This is docs/README"},
|
||||
}},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -495,8 +494,8 @@ func testViewRepoSymlink(t *testing.T) {
|
||||
err := git.ForceFastImport(t.Context(), repo.CodeStorageRepo(), []git.FastImportCommit{
|
||||
{
|
||||
Ref: "refs/heads/symlink", Message: "test", Files: []git.FastImportFile{
|
||||
{git.EntryModeSymlink, "README.md", "some/other/path/awefulcake.txt"},
|
||||
{git.EntryModeBlob, "some/other/path/awefulcake.txt", "text content"},
|
||||
{Mode: git.EntryModeSymlink, Path: "README.md", Content: "some/other/path/awefulcake.txt"},
|
||||
{Path: "some/other/path/awefulcake.txt", Content: "text content"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user