package lint import ( "go/parser" "go/token" "os" "path/filepath" "strconv" "strings" "testing" ) // preMoveRastrillo is rastrillo's module path before it moved to // amadan.net/rastrillo/rastrillo. Nothing after v0.23.0 was released // under it, so code importing it gets no rastrillo fix, and its own // checks cannot tell: Docs zoomed iOS on every tap of every field for a // month after rastrillo fixed it (polish audit r3, item 1). const preMoveRastrillo = "github.com/carlosframework/rastrillo" // preMoveAllowed is the one file that may still import it, the one // package it may import, and why: rastrillo/native's server takes the // pre-move path's *sessions.Sessions. Delete the entry when // native/server moves. var preMoveAllowed = map[string]string{ "internal/docs/native.go": preMoveRastrillo + "/sessions", } // TestNoPreMoveRastrillo fails on any import of rastrillo's pre-move // module path outside preMoveAllowed. func TestNoPreMoveRastrillo(t *testing.T) { root := repoRoot(t) fset := token.NewFileSet() err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error { if err != nil { return err } if d.IsDir() { if path != root && skipDir(d.Name()) { return filepath.SkipDir } return nil } if !strings.HasSuffix(path, ".go") { return nil } f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly) if err != nil { return err } rel, err := filepath.Rel(root, path) if err != nil { return err } rel = filepath.ToSlash(rel) for _, imp := range f.Imports { p, err := strconv.Unquote(imp.Path.Value) if err != nil { return err } if (p == preMoveRastrillo || strings.HasPrefix(p, preMoveRastrillo+"/")) && preMoveAllowed[rel] != p { t.Errorf("%s: imports %q, rastrillo's frozen pre-move path; use amadan.net/rastrillo/rastrillo", rel, p) } } return nil }) if err != nil { t.Fatalf("lint: walk %s: %v", root, err) } }