Remove DenylistImports (#23)

`DenylistImports` will be redundant once [gitea/pull/22412](https://github.com/go-gitea/gitea/pull/22412) has been merged.

Reviewed-on: https://gitea.com/gitea/gitea-vet/pulls/23
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: John Olheiser <john+gitea@jolheiser.com>
Co-authored-by: Jason Song <i@wolfogre.com>
Co-committed-by: Jason Song <i@wolfogre.com>
This commit is contained in:
Jason Song 2023-01-13 10:24:36 +08:00 committed by John Olheiser
parent 7a42a3666a
commit 2b1561217f
2 changed files with 0 additions and 47 deletions

View File

@ -1,46 +0,0 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package checks
import (
"strings"
"golang.org/x/tools/go/analysis"
)
var (
deniedImports = []string{"io/ioutil", "encoding/json", "gitea.com/gitea/go-crypto"}
DenylistImports = &analysis.Analyzer{
Name: "denylist_imports",
Doc: "check for denied imports",
Run: runDenylistImports,
}
)
func runDenylistImports(pass *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
for _, im := range file.Imports {
val := im.Path.Value
val = strings.TrimPrefix(val, `"`)
val = strings.TrimSuffix(val, `"`)
for _, deniedImport := range deniedImports {
if strings.HasPrefix(val, deniedImport) {
// Allow a exemption when there is a comment 'Allow "package_name" import'
allowed := false
for _, comment := range file.Comments {
if strings.Contains(comment.Text(), "Allow \""+val+"\" import") {
allowed = true
break
}
}
if !allowed {
pass.Reportf(im.Path.Pos(), `"`+val+"\" is not allowed to be imported")
}
}
}
}
}
return nil, nil
}

View File

@ -11,7 +11,6 @@ import (
func main() {
unitchecker.Main(
checks.DenylistImports,
checks.Imports,
checks.License,
checks.Migrations,