MCPcopy Index your code
hub / github.com/valyala/quicktemplate / validateImport

Function validateImport

parser/parser.go:902–921  ·  view source on GitHub ↗
(code []byte)

Source from the content-addressed store, hash-verified

900}
901
902func validateImport(code []byte) error {
903 codeStr := fmt.Sprintf("package foo\nimport %s", code)
904 fset := gotoken.NewFileSet()
905 f, err := goparser.ParseFile(fset, "", codeStr, 0)
906 if err != nil {
907 return err
908 }
909 for _, d := range f.Decls {
910 gd, ok := d.(*ast.GenDecl)
911 if !ok {
912 return fmt.Errorf("unexpected code found: %T. Expecting ast.GenDecl", d)
913 }
914 for _, s := range gd.Specs {
915 if _, ok := s.(*ast.ImportSpec); !ok {
916 return fmt.Errorf("unexpected code found: %T. Expecting ast.ImportSpec", s)
917 }
918 }
919 }
920 return nil
921}

Callers 1

parseImportMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…