gopatch
gopatch copied to clipboard
Refactoring and code transformation tool for Go.
Functionality to list matches without modifying the target files. User comments could be caught during the linting phase instead of their manual detection during the code review process. For example:...
`[...]` in function calls should match any and all generic function instantiations. ```diff @@ @@ -foo[...](42) +bar[...](42) ``` Should match: ``` foo(42) foo[int](42) foo[MyInt](42) ```
Elision does not seem to match variadic parameters - which also use the `...` notation. Below is a simple repro. Patch file (goal is to swap order of first 2...
For gopatch, currently the following are different: ``` var foo = 42 var ( foo = 42 ) ``` gopatch should understand decl groupings for types, consts, vars, and funcs...
We should support metavariables to match on literals. That is, to match on `"foo"` and `42` below. ``` x := "foo" const y = 42 ``` This will make it...
It's currently impossible to have a patch that introduces a new top-level declaration while modifying another one. For example, given, ``` func foo() { re := regexp.MustCompile("foo") // ... }...
We should support a `-d` flag to print the diff of what would be changed without changing anything. If the diff was non-empty, the program would exit with a non-zero...
We should support a `-l` flag to list matches of a patch without changing anything. This could be used to implement simple linters.
For simple, short patches, we should support a `-e` flag like sed with some automatic means of defining metavariables similar to `gofmt -r`.
Patches currently apply at matching "levels" in the AST. For example, consider the following patch. ```diff @@ @@ -func foo(...) { +func foo(...) error { ... if err != nil...