-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
perf: replace goheader linter with custom check
#37599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
silverwind
merged 31 commits into
go-gitea:main
from
silverwind:lint-go-replace-goheader
May 8, 2026
Merged
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 de88319
merge targets
silverwind c4357b0
chore: combine lint-go header check and golangci-lint into single stage
silverwind 01351e4
chore: preserve golangci-lint exit code over header check
silverwind 6f56264
fix: address copilot review feedback
silverwind 5d30738
refactor: simplify file read with os.ReadFile
silverwind ac2aa27
fix: build lint-go-header for host in lint-go-windows
silverwind 6e0d9a0
Merge branch 'main' into lint-go-replace-goheader
silverwind 9bbf547
refactor: extract lint-go orchestration to tools/lint-go.sh
silverwind 6a1cb97
refactor: consolidate lint-go targets through tools/lint-go.sh
silverwind 3475f75
refactor: inline lint-go.sh branches instead of array dispatch
silverwind 6c75a5b
refactor: inline exit-code capture into the same line
silverwind 9f6f4f4
refactor: pass GO from make and use it in lint-go.sh
silverwind df962f1
chore: drop orphaned goheader settings block
silverwind 8639048
fix
wxiaoguang f7df98a
fix
wxiaoguang 17f8753
fix: address review feedback on tools/lint-go-header.go
silverwind 5719a58
Merge branch 'main' into lint-go-replace-goheader
silverwind 4ccebfa
fix: skip top-level dirs by relative path
silverwind 9c60c59
fix
wxiaoguang 436902c
Apply suggestion from @silverwind
silverwind 8700e51
Apply suggestion from @wxiaoguang
wxiaoguang 65d154e
add lint-go-all.sh back
wxiaoguang 00182de
make "lint-go" to lint all
wxiaoguang 3ebe430
fix
wxiaoguang d3577be
fine tune
wxiaoguang 3ab0a37
fine tune
wxiaoguang a49302a
Merge branch 'main' into lint-go-replace-goheader
GiteaBot 5bab4db
Merge branch 'main' into lint-go-replace-goheader
silverwind e279ca6
Merge branch 'main' into lint-go-replace-goheader
GiteaBot 8b81aad
Merge branch 'main' into lint-go-replace-goheader
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
|
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()] { | ||
|
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() | ||
|
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) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.