(code []byte)
| 900 | } |
| 901 | |
| 902 | func 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…