summaryrefslogtreecommitdiffstats
path: root/vendor/code.gitea.io/gitea-vet/checks/license.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-08-15 19:13:07 +0200
committerGitHub <noreply@github.com>2020-08-15 13:13:07 -0400
commitee97e6a66a7bec9547af31c93a5eef7c19a32c54 (patch)
tree1143ebd8f6abd6027c52e99d71534f141eaecd8e /vendor/code.gitea.io/gitea-vet/checks/license.go
parenteb60a5d05478f56bf15220f49ed78f0f72af5698 (diff)
downloadgitea-ee97e6a66a7bec9547af31c93a5eef7c19a32c54.tar.gz
gitea-ee97e6a66a7bec9547af31c93a5eef7c19a32c54.zip
Update gitea-vet to v0.2.1 (#12282)
* change to new code location * vendor * tagged version v0.2.0 * gitea-vet v0.2.1 Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'vendor/code.gitea.io/gitea-vet/checks/license.go')
-rw-r--r--vendor/code.gitea.io/gitea-vet/checks/license.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/code.gitea.io/gitea-vet/checks/license.go b/vendor/code.gitea.io/gitea-vet/checks/license.go
new file mode 100644
index 0000000000..a3ae04767b
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/checks/license.go
@@ -0,0 +1,73 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package checks
+
+import (
+ "regexp"
+ "strings"
+
+ "golang.org/x/tools/go/analysis"
+)
+
+var (
+ header = regexp.MustCompile(`.*Copyright.*\d{4}.*(Gitea|Gogs)`)
+ goGenerate = "//go:generate"
+ buildTag = "// +build"
+)
+
+var License = &analysis.Analyzer{
+ Name: "license",
+ Doc: "check for a copyright header",
+ Run: runLicense,
+}
+
+func runLicense(pass *analysis.Pass) (interface{}, error) {
+ for _, file := range pass.Files {
+ if len(file.Comments) == 0 {
+ pass.Reportf(file.Pos(), "Copyright not found")
+ continue
+ }
+
+ if len(file.Comments[0].List) == 0 {
+ pass.Reportf(file.Pos(), "Copyright not found or wrong")
+ continue
+ }
+
+ commentGroup := 0
+ if strings.HasPrefix(file.Comments[0].List[0].Text, goGenerate) {
+ if len(file.Comments[0].List) > 1 {
+ pass.Reportf(file.Pos(), "Must be an empty line between the go:generate and the Copyright")
+ continue
+ }
+ commentGroup++
+ }
+
+ if strings.HasPrefix(file.Comments[0].List[0].Text, buildTag) {
+ commentGroup++
+ }
+
+ if len(file.Comments) < commentGroup+1 {
+ pass.Reportf(file.Pos(), "Copyright not found")
+ continue
+ }
+
+ if len(file.Comments[commentGroup].List) < 1 {
+ pass.Reportf(file.Pos(), "Copyright not found or wrong")
+ continue
+ }
+
+ var check bool
+ for _, comment := range file.Comments[commentGroup].List {
+ if header.MatchString(comment.Text) {
+ check = true
+ }
+ }
+
+ if !check {
+ pass.Reportf(file.Pos(), "Copyright did not match check")
+ }
+ }
+ return nil, nil
+}