Check SPDX-License-Identifier (#21)

Check `SPDX-License-Identifier` in file headers.

Related to https://github.com/go-gitea/gitea/pull/21840

Co-authored-by: Jason Song <i@wolfogre.com>
Reviewed-on: https://gitea.com/gitea/gitea-vet/pulls/21
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Xinyu Zhou <i@sourcehut.net>
Co-authored-by: Jason Song <wolfogre@noreply.gitea.io>
Co-committed-by: Jason Song <wolfogre@noreply.gitea.io>
This commit is contained in:
Jason Song 2022-12-01 23:58:05 +08:00 committed by Lunny Xiao
parent 854133ff01
commit 4c10dca949
8 changed files with 22 additions and 24 deletions

View File

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

View File

@ -17,6 +17,6 @@ vet: build
lint: lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
export BINARY="golangci-lint"; \ 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 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. // Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package checks package checks

View File

@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package checks package checks

View File

@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package checks package checks
@ -12,7 +11,9 @@ import (
) )
var ( 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" goGenerate = "//go:generate"
buildTag = "// +build" buildTag = "// +build"
) )
@ -58,16 +59,22 @@ func runLicense(pass *analysis.Pass) (interface{}, error) {
continue continue
} }
var check bool var copyright, identifier bool
for _, comment := range file.Comments[commentGroup].List { for _, comment := range file.Comments[commentGroup].List {
if header.MatchString(comment.Text) { if copyrightRegx.MatchString(comment.Text) {
check = true copyright = true
}
if identifierRegx.MatchString(comment.Text) {
identifier = true
} }
} }
if !check { if !copyright {
pass.Reportf(file.Pos(), "Copyright did not match check") 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 return nil, nil
} }

View File

@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package checks package checks

View File

@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package checks package checks

View File

@ -1,6 +1,5 @@
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // SPDX-License-Identifier: MIT
// license that can be found in the LICENSE file.
package main package main