mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 18:23:42 +00:00
chore: misc go 1.27 tweaks (#39069)
Follow-up to https://github.com/go-gitea/gitea/pull/39068, which disabled `modernize` entirely. - re-enable `modernize`, with only the new `embedlit` rule disabled. It flattens embedded struct literals across ~145 files, and orphans imports in 6 of them that the fixer does not remove - apply the rest of the suite: `errors.AsType`, `reflect.TypeAssert`, `strings.Cut`, and dropping the legacy import comment - use the new stdlib `uuid` package, `github.com/google/uuid` becomes indirect - use `strings.CutLast` in place of manual `LastIndex` slicing in label scopes, email domains and the diff tree list - take the header lint skip dirs from the `go.mod` `ignore` directive and skip dot-directories, instead of hardcoding the list Assisted-by: Claude Code:claude-opus-5
This commit is contained in:
+28
-9
@@ -12,26 +12,45 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/modfile"
|
||||
)
|
||||
|
||||
// goModIgnoredDirs returns the go.mod "ignore" directories, which the go tool skips but a filesystem walk does not.
|
||||
func goModIgnoredDirs() (map[string]bool, error) {
|
||||
data, err := os.ReadFile("go.mod")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mod, err := modfile.Parse("go.mod", data, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dirs := make(map[string]bool, len(mod.Ignore))
|
||||
for _, ignore := range mod.Ignore {
|
||||
dirs[filepath.ToSlash(filepath.Clean(ignore.Path))] = true
|
||||
}
|
||||
return dirs, nil
|
||||
}
|
||||
|
||||
func lintGoHeader() bool {
|
||||
headerRE := regexp.MustCompile(`^(// (Copyright [^\n]+|All rights reserved\.)\n)*// Copyright \d{4} (The Gogs Authors|The Gitea Authors|Gitea Authors|Gitea)\.( All rights reserved\.)?\n(// (Copyright [^\n]+|All rights reserved\.)\n)*// SPDX-License-Identifier: [\w.-]+`)
|
||||
generatedRE := regexp.MustCompile(`(?m)^// (Code|This file is) [Gg]enerated.*DO NOT EDIT`)
|
||||
skipDirs := map[string]bool{
|
||||
".git": true,
|
||||
".venv": true,
|
||||
"node_modules": true,
|
||||
"public": true,
|
||||
"vendor": true,
|
||||
"web_src": true,
|
||||
skipDirs, err := goModIgnoredDirs()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
return false
|
||||
}
|
||||
root, bad := ".", 0
|
||||
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
err = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
if rel, _ := filepath.Rel(root, path); skipDirs[filepath.ToSlash(rel)] {
|
||||
if path == root {
|
||||
return nil
|
||||
}
|
||||
if skipDirs[filepath.ToSlash(path)] || strings.HasPrefix(d.Name(), ".") {
|
||||
return fs.SkipDir
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user