diff --git a/cmd/gorename/main.go b/cmd/gorename/main.go index aeee13d25e..255eb49dcc 100644 --- a/cmd/gorename/main.go +++ b/cmd/gorename/main.go @@ -64,6 +64,8 @@ Flags: (In due course this bug will be fixed by moving certain analyses into the type-checker.) +-dryrun causes the tool to report conflicts but not update any files. + -v enables verbose logging. gorename automatically computes the set of packages that might be @@ -82,7 +84,7 @@ Examples: % gorename -offset file.go:#123 -to foo - Rename the object whose identifer is at byte offset 123 within file file.go. + Rename the object whose identifier is at byte offset 123 within file file.go. % gorename -from '(bytes.Buffer).Len' -to Size @@ -91,7 +93,6 @@ Examples: ---- TODO ---- Correctness: -- implement remaining safety checks. - handle dot imports correctly - document limitations (reflection, 'implements' guesswork). - sketch a proof of exhaustiveness. @@ -113,7 +114,7 @@ Features: all local variables of a given type, all PkgNames for a given package. - emit JSON output for other editors and tools. -- integration support for editors other than Emacs. +- integration with editors other than Emacs. ` func main() { diff --git a/refactor/rename/rename.go b/refactor/rename/rename.go index 5563792cd1..53d88801ec 100644 --- a/refactor/rename/rename.go +++ b/refactor/rename/rename.go @@ -32,10 +32,10 @@ var ( // It may even cause gorename to crash. TODO(adonovan): fix that. Force bool - // DryRun causes the patch to be displayed but not applied. + // DryRun causes the tool to report conflicts but not update any files. DryRun bool - // ConfictError is returned by Main when it aborts the renaming due to conflicts. + // ConflictError is returned by Main when it aborts the renaming due to conflicts. // (It is distinguished because the interesting errors are the conflicts themselves.) ConflictError = errors.New("renaming aborted due to conflicts") @@ -280,7 +280,7 @@ func (r *renamer) update() error { info.Pkg.Path()) } } - if err := rewriteFile(r.iprog.Fset, f, tokenFile.Name(), tokenFile.Name()+".prename"); err != nil { + if err := rewriteFile(r.iprog.Fset, f, tokenFile.Name()); err != nil { fmt.Fprintf(os.Stderr, "Error: %s.\n", err) nerrs++ } @@ -304,7 +304,8 @@ func plural(n int) string { return "" } -var rewriteFile = func(fset *token.FileSet, f *ast.File, orig, backup string) (err error) { +var rewriteFile = func(fset *token.FileSet, f *ast.File, orig string) (err error) { + backup := orig + ".prename" // TODO(adonovan): print packages and filenames in a form useful // to editors (so they can reload files). if Verbose { diff --git a/refactor/rename/rename_test.go b/refactor/rename/rename_test.go index ec5b0cc422..23695d8a91 100644 --- a/refactor/rename/rename_test.go +++ b/refactor/rename/rename_test.go @@ -372,7 +372,7 @@ var _ interface {f()} = C(0) } func TestRewrites(t *testing.T) { - defer func(savedRewriteFile func(*token.FileSet, *ast.File, string, string) error) { + defer func(savedRewriteFile func(*token.FileSet, *ast.File, string) error) { rewriteFile = savedRewriteFile }(rewriteFile) @@ -654,7 +654,7 @@ func f(z interface{}) { } got := make(map[string]string) - rewriteFile = func(fset *token.FileSet, f *ast.File, orig, backup string) error { + rewriteFile = func(fset *token.FileSet, f *ast.File, orig string) error { var out bytes.Buffer if err := format.Node(&out, fset, f); err != nil { return err