Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
45c7833
perf: replace goheader linter with custom check
silverwind May 7, 2026
de88319
merge targets
silverwind May 8, 2026
c4357b0
chore: combine lint-go header check and golangci-lint into single stage
silverwind May 8, 2026
01351e4
chore: preserve golangci-lint exit code over header check
silverwind May 8, 2026
6f56264
fix: address copilot review feedback
silverwind May 8, 2026
5d30738
refactor: simplify file read with os.ReadFile
silverwind May 8, 2026
ac2aa27
fix: build lint-go-header for host in lint-go-windows
silverwind May 8, 2026
6e0d9a0
Merge branch 'main' into lint-go-replace-goheader
silverwind May 8, 2026
9bbf547
refactor: extract lint-go orchestration to tools/lint-go.sh
silverwind May 8, 2026
6a1cb97
refactor: consolidate lint-go targets through tools/lint-go.sh
silverwind May 8, 2026
3475f75
refactor: inline lint-go.sh branches instead of array dispatch
silverwind May 8, 2026
6c75a5b
refactor: inline exit-code capture into the same line
silverwind May 8, 2026
9f6f4f4
refactor: pass GO from make and use it in lint-go.sh
silverwind May 8, 2026
df962f1
chore: drop orphaned goheader settings block
silverwind May 8, 2026
8639048
fix
wxiaoguang May 8, 2026
f7df98a
fix
wxiaoguang May 8, 2026
17f8753
fix: address review feedback on tools/lint-go-header.go
silverwind May 8, 2026
5719a58
Merge branch 'main' into lint-go-replace-goheader
silverwind May 8, 2026
4ccebfa
fix: skip top-level dirs by relative path
silverwind May 8, 2026
9c60c59
fix
wxiaoguang May 8, 2026
436902c
Apply suggestion from @silverwind
silverwind May 8, 2026
8700e51
Apply suggestion from @wxiaoguang
wxiaoguang May 8, 2026
65d154e
add lint-go-all.sh back
wxiaoguang May 8, 2026
00182de
make "lint-go" to lint all
wxiaoguang May 8, 2026
3ebe430
fix
wxiaoguang May 8, 2026
d3577be
fine tune
wxiaoguang May 8, 2026
3ab0a37
fine tune
wxiaoguang May 8, 2026
a49302a
Merge branch 'main' into lint-go-replace-goheader
GiteaBot May 8, 2026
5bab4db
Merge branch 'main' into lint-go-replace-goheader
silverwind May 8, 2026
e279ca6
Merge branch 'main' into lint-go-replace-goheader
GiteaBot May 8, 2026
8b81aad
Merge branch 'main' into lint-go-replace-goheader
GiteaBot May 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ linters:
- forbidigo
- gocheckcompilerdirectives
- gocritic
- goheader
- govet
- ineffassign
- mirror
Comment thread
silverwind marked this conversation as resolved.
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,15 @@ lint-spell-fix: ## lint spelling and fix issues

.PHONY: lint-go
lint-go: ## lint go files
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
@$(GO) run tools/lint-go-header.go; header=$$?; \
$(GO) run $(GOLANGCI_LINT_PACKAGE) run; lint=$$?; \
exit $$((lint ? lint : header))
Comment thread
silverwind marked this conversation as resolved.
Outdated

.PHONY: lint-go-fix
lint-go-fix: ## lint go files and fix issues
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
@$(GO) run tools/lint-go-header.go; header=$$?; \
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix; lint=$$?; \
exit $$((lint ? lint : header))

# workaround step for the lint-go-windows CI task because 'go run' can not
# have distinct GOOS/GOARCH for its build and run steps
Expand Down
3 changes: 3 additions & 0 deletions build/generate-gitignores.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build ignore

package main
Expand Down
4 changes: 2 additions & 2 deletions models/db/driver_sqlite_mattn.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build sqlite_mattn && sqlite_unlock_notify

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build sqlite_mattn && sqlite_unlock_notify

package db

import (
Expand Down
4 changes: 2 additions & 2 deletions models/db/driver_sqlite_modernc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build !sqlite_mattn

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build !sqlite_mattn

// modernc driver is chosen as the default one (compared to mattn, ncruces)
// * mattn was used as default, but it requires CGO
// * the CI times are almost the same for these three (race detector must be disabled)
Expand Down
4 changes: 2 additions & 2 deletions modules/auth/pam/pam_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:build pam

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build pam

package pam

import (
Expand Down
3 changes: 2 additions & 1 deletion modules/charset/ambiguous_gen.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

// This file is generated by modules/charset/generate/generate.go DO NOT EDIT

package charset

import "unicode"
Expand Down
10 changes: 6 additions & 4 deletions modules/charset/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ func main() {
generateInvisible()
}

var templateAmbiguous = template.Must(template.New("ambiguousTemplate").Parse(`// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
// Copyright 2026 The Gitea Authors. All rights reserved.
var templateAmbiguous = template.Must(template.New("ambiguousTemplate").Parse(`// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

// This file is generated by modules/charset/generate/generate.go DO NOT EDIT

package charset

import "unicode"
Expand Down Expand Up @@ -179,10 +180,11 @@ func newAmbiguousTableMap() map[string]*AmbiguousTable {
}
`))

var generatorInvisible = template.Must(template.New("invisibleTemplate").Parse(`// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
// Copyright 2026 The Gitea Authors. All rights reserved.
var generatorInvisible = template.Must(template.New("invisibleTemplate").Parse(`// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

// This file is generated by modules/charset/generate/generate.go DO NOT EDIT

package charset

import "unicode"
Expand Down
3 changes: 2 additions & 1 deletion modules/charset/invisible_gen.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

// This file is generated by modules/charset/generate/generate.go DO NOT EDIT
Comment thread
silverwind marked this conversation as resolved.
Outdated

package charset

import "unicode"
Expand Down
67 changes: 67 additions & 0 deletions tools/lint-go-header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build ignore

package main

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"
)

var 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.-]+`)

var skipDirs = map[string]bool{
".git": true,
".venv": true,
"node_modules": true,
"public": true,
Comment thread
silverwind marked this conversation as resolved.
Outdated
"web_src": true,
}

func main() {
root := "."
if len(os.Args) > 1 {
root = os.Args[1]
}

bad := 0
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
if skipDirs[d.Name()] {
Comment thread
silverwind marked this conversation as resolved.
Outdated
return fs.SkipDir
}
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}
f, err := os.Open(path)
if err != nil {
return err
}
buf := make([]byte, 1024)
n, _ := f.Read(buf)
f.Close()
Comment thread
silverwind marked this conversation as resolved.
Outdated
if !headerRE.Match(buf[:n]) {
fmt.Printf("%s: missing or invalid copyright header\n", path)
bad++
}
return nil
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
if bad > 0 {
os.Exit(1)
}
}
Loading