mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-01 14:56:54 +01:00
eb37f14923
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>
47 lines
890 B
Go
47 lines
890 B
Go
// 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)
|
|
}
|