Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Here's the code we use to refactor ```go func main() { _ = filepath.Walk(".", func(path string, info fs.FileInfo, err error) error { if !strings.HasSuffix(path, "_test.go") || strings.HasPrefix(path, "lib/proto/") { return nil } fmt.Println(path) f, _ := os.ReadFile(path) ms := regexp.MustCompile(`(?m)^func \(t T\)`).FindAllIndex(f, -1) for _, m := range ms { cmd := fmt.Sprintf("gopls -remote=127.0.0.1:8888 rename -w %s:#%d g", path, m[0]+6) utils.ExecLine(cmd) } f, _ = os.ReadFile(path) f = regexp.MustCompile(`(?m)^func \(g T\) ([^\s]+)\(\) \{`). ReplaceAll(f, []byte("func Test$1(t *testing.T) {\n\tg := setup(t)\n")) err = os.WriteFile(path, f, info.Mode()) return err }) } ```
- Loading branch information