diff options
author | 6543 <6543@obermui.de> | 2020-08-15 19:13:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-15 13:13:07 -0400 |
commit | ee97e6a66a7bec9547af31c93a5eef7c19a32c54 (patch) | |
tree | 1143ebd8f6abd6027c52e99d71534f141eaecd8e /vendor/code.gitea.io/gitea-vet/checks/imports.go | |
parent | eb60a5d05478f56bf15220f49ed78f0f72af5698 (diff) | |
download | gitea-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/imports.go')
-rw-r--r-- | vendor/code.gitea.io/gitea-vet/checks/imports.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/code.gitea.io/gitea-vet/checks/imports.go b/vendor/code.gitea.io/gitea-vet/checks/imports.go new file mode 100644 index 0000000000..15563c8543 --- /dev/null +++ b/vendor/code.gitea.io/gitea-vet/checks/imports.go @@ -0,0 +1,46 @@ +// 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 ( + "strings" + + "golang.org/x/tools/go/analysis" +) + +var Imports = &analysis.Analyzer{ + Name: "imports", + Doc: "check for import order", + Run: runImports, +} + +func runImports(pass *analysis.Pass) (interface{}, error) { + for _, file := range pass.Files { + level := 0 + for _, im := range file.Imports { + var lvl int + val := im.Path.Value + switch { + case importHasPrefix(val, "code.gitea.io"): + lvl = 2 + case strings.Contains(val, "."): + lvl = 3 + default: + lvl = 1 + } + + if lvl < level { + pass.Reportf(file.Pos(), "Imports are sorted wrong") + break + } + level = lvl + } + } + return nil, nil +} + +func importHasPrefix(s, p string) bool { + return strings.HasPrefix(s, "\""+p) +} |