Split migration check to Deps and Imports (#9)
Relax restrictions on modules/structs to disallow direct import of structs but allow dependency. As discussed in https://github.com/go-gitea/gitea/pull/12282#issuecomment-664049963 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/gitea-vet/pulls/9 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
900a9f5eac
commit
5233fe7746
|
@ -18,10 +18,14 @@ var Migrations = &analysis.Analyzer{
|
|||
Run: checkMigrations,
|
||||
}
|
||||
|
||||
var migrationBlacklist = []string{
|
||||
"code.gitea.io/gitea/models",
|
||||
"code.gitea.io/gitea/modules/structs",
|
||||
}
|
||||
var (
|
||||
migrationDepBlockList = []string{
|
||||
"code.gitea.io/gitea/models",
|
||||
}
|
||||
migrationImpBlockList = []string{
|
||||
"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") {
|
||||
|
@ -40,8 +44,22 @@ func checkMigrations(pass *analysis.Pass) (interface{}, error) {
|
|||
|
||||
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)
|
||||
if stringInSlice(dep, migrationDepBlockList) {
|
||||
pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot depend on the following packages: %s", migrationDepBlockList)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
impsCmd := exec.Command("go", "list", "-f", `{{join .Imports "\n"}}`, "code.gitea.io/gitea/models/migrations")
|
||||
impsOut, err := impsCmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imps := strings.Split(string(impsOut), "\n")
|
||||
for _, imp := range imps {
|
||||
if stringInSlice(imp, migrationImpBlockList) {
|
||||
pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot import the following packages: %s", migrationImpBlockList)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue