Check SPDX-License-Identifier #21

Merged
lunny merged 3 commits from wolfogre/gitea-vet:featrue/spdx-license-identifier into master 2022-12-01 15:58:05 +00:00
8 changed files with 22 additions and 24 deletions

View File

@ -1,6 +1,5 @@
linters:
enable:
- deadcode
- dogsled
- dupl
- errcheck
@ -9,15 +8,12 @@ linters:
- gocritic
- gocyclo
- gofmt
- golint
- revive
- gosimple
- govet
- maligned
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck

View File

@ -17,6 +17,6 @@ vet: build
lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
export BINARY="golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin v1.24.0; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin v1.50.1; \
fi
golangci-lint run --timeout 5m
golangci-lint run --timeout 5m

View File

@ -1,6 +1,5 @@
// Copyright 2022 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.
// SPDX-License-Identifier: MIT
package checks

View File

@ -1,6 +1,5 @@
// 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.
// SPDX-License-Identifier: MIT
package checks

View File

@ -1,6 +1,5 @@
// 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.
// SPDX-License-Identifier: MIT
package checks
@ -12,7 +11,9 @@ import (
)
var (
header = regexp.MustCompile(`.*Copyright.*\d{4}.*(Gitea|Gogs)`)
copyrightRegx = regexp.MustCompile(`.*Copyright.*\d{4}.*(Gitea|Gogs)`)
identifierRegx = regexp.MustCompile(`SPDX-License-Identifier: [\w.-]+`)
goGenerate = "//go:generate"
buildTag = "// +build"
)
@ -58,16 +59,22 @@ func runLicense(pass *analysis.Pass) (interface{}, error) {
continue
}
var check bool
var copyright, identifier bool
for _, comment := range file.Comments[commentGroup].List {
if header.MatchString(comment.Text) {
check = true
if copyrightRegx.MatchString(comment.Text) {
copyright = true
}
if identifierRegx.MatchString(comment.Text) {
identifier = true
}
}
if !check {
if !copyright {
pass.Reportf(file.Pos(), "Copyright did not match check")
}
if !identifier {
pass.Reportf(file.Pos(), "SPDX-License-Identifier did not match check")
}
}
return nil, nil
}

View File

@ -1,6 +1,5 @@
// 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.
// SPDX-License-Identifier: MIT
package checks

View File

@ -1,6 +1,5 @@
// 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.
// SPDX-License-Identifier: MIT
package checks

View File

@ -1,6 +1,5 @@
// 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.
// SPDX-License-Identifier: MIT
package main