1
0
Fork 0

Update gitea-vet v0.2.0 (#164)

tagged version v0.2.0

make vendor

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/164
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-07-21 16:17:52 +00:00 committed by techknowlogick
parent edd180a8f5
commit eb37f14923
22 changed files with 310 additions and 51 deletions

View File

@ -71,7 +71,7 @@ vet:
# Default vet
$(GO) vet -mod=vendor $(PACKAGES)
# Custom vet
$(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
$(GO) build -mod=vendor code.gitea.io/gitea-vet
$(GO) vet -vettool=gitea-vet $(PACKAGES)
.PHONY: lint

View File

@ -10,5 +10,5 @@ package main
import (
// for vet
_ "gitea.com/jolheiser/gitea-vet"
_ "code.gitea.io/gitea-vet"
)

4
go.mod
View File

@ -3,8 +3,8 @@ module code.gitea.io/tea
go 1.12
require (
code.gitea.io/gitea-vet v0.2.0
code.gitea.io/sdk/gitea v0.12.1
gitea.com/jolheiser/gitea-vet v0.1.0
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-git/go-git/v5 v5.1.0
@ -17,6 +17,6 @@ require (
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed // indirect
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a // indirect
gopkg.in/yaml.v2 v2.3.0
)

8
go.sum
View File

@ -1,7 +1,7 @@
code.gitea.io/gitea-vet v0.2.0 h1:xkUePzbHI8e0qp4Aly4GBSd0+6cqEMVTrdZq57fPozo=
code.gitea.io/gitea-vet v0.2.0/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
code.gitea.io/sdk/gitea v0.12.1 h1:bMgjEqPnNX/i6TpVwXwpjJtFOnUSuC9P6yy/jjy8sjY=
code.gitea.io/sdk/gitea v0.12.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
gitea.com/jolheiser/gitea-vet v0.1.0 h1:gJEms9YWbIcrPOEmDOJ+5JZXCYFxNpwxlI73uRulAi4=
gitea.com/jolheiser/gitea-vet v0.1.0/go.mod h1:2Oa6TAdEp1N/38oBNh3ZeiSEER60D/CeDaBFv2sdH58=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
@ -125,8 +125,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224 h1:azwY/v0y0K4mFHVsg5+UrTgchqALYWpqVo6vL5OmkmI=
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed h1:+qzWo37K31KxduIYaBeMqJ8MUOyTayOQKpH9aDPLMSY=
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a h1:kVMPw4f6EVqYdfGQTedjrpw1dbE2PEMfw4jwXsNdn9s=
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=

30
vendor/code.gitea.io/gitea-vet/.changelog.yml generated vendored Normal file
View File

@ -0,0 +1,30 @@
# The full repository name
repo: gitea/gitea-vet
# Service type (gitea or github)
service: gitea
# Base URL for Gitea instance if using gitea service type (optional)
base-url: https://gitea.com
# Changelog groups and which labeled PRs to add to each group
groups:
-
name: BREAKING
labels:
- breaking
-
name: FEATURES
labels:
- feature
-
name: BUGFIXES
labels:
- bug
-
name: ENHANCEMENTS
labels:
- enhancement
# regex indicating which labels to skip for the changelog
skip-labels: skip-changelog|backport\/.+

45
vendor/code.gitea.io/gitea-vet/.drone.yml generated vendored Normal file
View File

@ -0,0 +1,45 @@
---
kind: pipeline
name: compliance
platform:
os: linux
arch: arm64
trigger:
event:
- pull_request
steps:
- name: check
pull: always
image: golang:1.14
environment:
GOPROXY: https://goproxy.cn
commands:
- make build
- make lint
- make vet
---
kind: pipeline
name: build-master
platform:
os: linux
arch: amd64
trigger:
branch:
- master
event:
- push
steps:
- name: build
pull: always
image: techknowlogick/xgo:latest
environment:
GOPROXY: https://goproxy.cn
commands:
- make build

23
vendor/code.gitea.io/gitea-vet/.golangci.yml generated vendored Normal file
View File

@ -0,0 +1,23 @@
linters:
enable:
- deadcode
- dogsled
- dupl
- errcheck
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- golint
- gosimple
- govet
- maligned
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck

6
vendor/code.gitea.io/gitea-vet/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,6 @@
## [0.2.0](https://gitea.com/gitea/gitea-vet/pulls?q=&type=all&state=closed&milestone=1272) - 2020-07-20
* FEATURES
* Add migrations check (#5)
* BUGFIXES
* Correct Import Paths (#6)

22
vendor/code.gitea.io/gitea-vet/Makefile generated vendored Normal file
View File

@ -0,0 +1,22 @@
GO ?= go
.PHONY: build
build:
$(GO) build
.PHONY: fmt
fmt:
$(GO) fmt ./...
.PHONY: vet
vet: build
$(GO) vet ./...
$(GO) vet -vettool=gitea-vet ./...
.PHONY: lint
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; \
fi
golangci-lint run --timeout 5m

11
vendor/code.gitea.io/gitea-vet/README.md generated vendored Normal file
View File

@ -0,0 +1,11 @@
# gitea-vet
[![Build Status](https://drone.gitea.com/api/badges/gitea/gitea-vet/status.svg)](https://drone.gitea.com/gitea/gitea-vet)
`go vet` tool for Gitea
| Analyzer | Description |
|------------|-----------------------------------------------------------------------------|
| Imports | Checks for import sorting. stdlib->code.gitea.io->other |
| License | Checks file headers for some form of `Copyright...YYYY...Gitea/Gogs` |
| Migrations | Checks for black-listed packages in `code.gitea.io/gitea/models/migrations` |

View File

@ -12,7 +12,7 @@ import (
var Imports = &analysis.Analyzer{
Name: "imports",
Doc: "check for import order.",
Doc: "check for import order",
Run: runImports,
}
@ -22,11 +22,12 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
for _, im := range file.Imports {
var lvl int
val := im.Path.Value
if importHasPrefix(val, "code.gitea.io") {
switch {
case importHasPrefix(val, "code.gitea.io"):
lvl = 2
} else if strings.Contains(val, ".") {
case strings.Contains(val, "."):
lvl = 3
} else {
default:
lvl = 1
}
@ -43,12 +44,3 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
func importHasPrefix(s, p string) bool {
return strings.HasPrefix(s, "\""+p)
}
func sliceHasPrefix(s string, prefixes ...string) bool {
for _, p := range prefixes {
if importHasPrefix(s, p) {
return true
}
}
return false
}

View File

@ -19,7 +19,7 @@ var (
var License = &analysis.Analyzer{
Name: "license",
Doc: "check for a copyright header.",
Doc: "check for a copyright header",
Run: runLicense,
}

59
vendor/code.gitea.io/gitea-vet/checks/migrations.go generated vendored Normal file
View File

@ -0,0 +1,59 @@
// 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 (
"errors"
"os/exec"
"strings"
"golang.org/x/tools/go/analysis"
)
var Migrations = &analysis.Analyzer{
Name: "migrations",
Doc: "check migrations for black-listed packages.",
Run: checkMigrations,
}
var migrationBlacklist = []string{
"code.gitea.io/gitea/models",
"code.gitea.io/gitea/modules/structs",
}
func checkMigrations(pass *analysis.Pass) (interface{}, error) {
if !strings.EqualFold(pass.Pkg.Path(), "code.gitea.io/gitea/models/migrations") {
return nil, nil
}
if _, err := exec.LookPath("go"); err != nil {
return nil, errors.New("go was not found in the PATH")
}
depsCmd := exec.Command("go", "list", "-f", `{{join .Deps "\n"}}`, "code.gitea.io/gitea/models/migrations")
depsOut, err := depsCmd.Output()
if err != nil {
return nil, err
}
deps := strings.Split(string(depsOut), "\n")
for _, dep := range deps {
if stringInSlice(dep, migrationBlacklist) {
pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot depend on the following packages: %s", migrationBlacklist)
return nil, nil
}
}
return nil, nil
}
func stringInSlice(needle string, haystack []string) bool {
for _, h := range haystack {
if strings.EqualFold(needle, h) {
return true
}
}
return false
}

View File

@ -1,4 +1,4 @@
module gitea.com/jolheiser/gitea-vet
module code.gitea.io/gitea-vet
go 1.14

View File

@ -5,7 +5,8 @@
package main
import (
"gitea.com/jolheiser/gitea-vet/checks"
"code.gitea.io/gitea-vet/checks"
"golang.org/x/tools/go/analysis/unitchecker"
)
@ -13,5 +14,6 @@ func main() {
unitchecker.Main(
checks.Imports,
checks.License,
checks.Migrations,
)
}

View File

@ -1,7 +0,0 @@
.PHONY: build
build:
go build
.PHONY: fmt
fmt:
go fmt ./...

View File

@ -1,7 +0,0 @@
# gitea-vet
`go vet` tool for Gitea
| Analyzer | Description |
|----------|---------------------------------------------------------------------|
| Imports | Checks for import sorting. stdlib->code.gitea.io->other |
| License | Checks file headers for some form of `Copyright...YYYY...Gitea/Gogs`|

View File

@ -16,6 +16,11 @@ import (
"golang.org/x/tools/go/ast/astutil"
)
var (
GetTypeErrors func(p interface{}) []types.Error
SetTypeErrors func(p interface{}, errors []types.Error)
)
func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos {
// Get the end position for the type error.
offset, end := fset.PositionFor(start, false).Offset, start
@ -79,9 +84,95 @@ func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Ty
default:
return ast.NewIdent(t.Name())
}
case *types.Pointer:
x := TypeExpr(fset, f, pkg, t.Elem())
if x == nil {
return nil
}
return &ast.UnaryExpr{
Op: token.MUL,
X: x,
}
case *types.Array:
elt := TypeExpr(fset, f, pkg, t.Elem())
if elt == nil {
return nil
}
return &ast.ArrayType{
Len: &ast.BasicLit{
Kind: token.INT,
Value: fmt.Sprintf("%d", t.Len()),
},
Elt: elt,
}
case *types.Slice:
elt := TypeExpr(fset, f, pkg, t.Elem())
if elt == nil {
return nil
}
return &ast.ArrayType{
Elt: elt,
}
case *types.Map:
key := TypeExpr(fset, f, pkg, t.Key())
value := TypeExpr(fset, f, pkg, t.Elem())
if key == nil || value == nil {
return nil
}
return &ast.MapType{
Key: key,
Value: value,
}
case *types.Chan:
dir := ast.ChanDir(t.Dir())
if t.Dir() == types.SendRecv {
dir = ast.SEND | ast.RECV
}
value := TypeExpr(fset, f, pkg, t.Elem())
if value == nil {
return nil
}
return &ast.ChanType{
Dir: dir,
Value: value,
}
case *types.Signature:
var params []*ast.Field
for i := 0; i < t.Params().Len(); i++ {
p := TypeExpr(fset, f, pkg, t.Params().At(i).Type())
if p == nil {
return nil
}
params = append(params, &ast.Field{
Type: p,
Names: []*ast.Ident{
{
Name: t.Params().At(i).Name(),
},
},
})
}
var returns []*ast.Field
for i := 0; i < t.Results().Len(); i++ {
r := TypeExpr(fset, f, pkg, t.Results().At(i).Type())
if r == nil {
return nil
}
returns = append(returns, &ast.Field{
Type: r,
})
}
return &ast.FuncType{
Params: &ast.FieldList{
List: params,
},
Results: &ast.FieldList{
List: returns,
},
}
case *types.Named:
if t.Obj().Pkg() == nil {
return nil
return ast.NewIdent(t.Obj().Name())
}
if t.Obj().Pkg() == pkg {
return ast.NewIdent(t.Obj().Name())
@ -104,19 +195,11 @@ func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Ty
X: ast.NewIdent(pkgName),
Sel: ast.NewIdent(t.Obj().Name()),
}
case *types.Pointer:
return &ast.UnaryExpr{
Op: token.MUL,
X: TypeExpr(fset, f, pkg, t.Elem()),
}
default:
return nil // TODO: anonymous structs, but who does that
}
}
var GetTypeErrors = func(p interface{}) []types.Error { return nil }
var SetTypeErrors = func(p interface{}, errors []types.Error) {}
type TypeErrorPass string
const (

8
vendor/modules.txt vendored
View File

@ -1,8 +1,8 @@
# code.gitea.io/gitea-vet v0.2.0
code.gitea.io/gitea-vet
code.gitea.io/gitea-vet/checks
# code.gitea.io/sdk/gitea v0.12.1
code.gitea.io/sdk/gitea
# gitea.com/jolheiser/gitea-vet v0.1.0
gitea.com/jolheiser/gitea-vet
gitea.com/jolheiser/gitea-vet/checks
# github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1
github.com/araddon/dateparse
# github.com/cpuguy83/go-md2man/v2 v2.0.0
@ -129,7 +129,7 @@ golang.org/x/sys/cpu
golang.org/x/sys/internal/unsafeheader
golang.org/x/sys/unix
golang.org/x/sys/windows
# golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed
# golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a
golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/internal/analysisflags
golang.org/x/tools/go/analysis/internal/facts