Fix import sorting and add README

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
jolheiser 2020-03-24 22:56:58 -05:00
parent 92e361fc3d
commit d1cfced920
No known key found for this signature in database
GPG Key ID: B853ADA5DA7BBF7A
2 changed files with 16 additions and 5 deletions

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# 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

@ -22,12 +22,12 @@ func run(pass *analysis.Pass) (interface{}, error) {
for _, im := range file.Imports {
var lvl int
val := im.Path.Value
if strings.HasPrefix(val, "code.gitea.io") {
lvl = 1
} else if sliceHasPrefix(val, "xorm.io", "github.com") {
if importHasPrefix(val, "code.gitea.io") {
lvl = 2
} else {
} else if sliceHasPrefix(val, "xorm.io", "github.com") {
lvl = 3
} else {
lvl = 1
}
if lvl < level {
@ -40,9 +40,13 @@ func run(pass *analysis.Pass) (interface{}, error) {
return nil, nil
}
func importHasPrefix(s, p string) bool {
return strings.HasPrefix(s, "\""+p)
}
func sliceHasPrefix(s string, prefixes ...string) bool {
for _, p := range prefixes {
if strings.HasPrefix(s, p) {
if importHasPrefix(s, p) {
return true
}
}