Repository: mvdan/gofumpt
Pull request #175 (2021-12-06 10:54:04)

Add Emacs installtion instruction

mvdan: Sounds good, thanks! Would you mind placing it under the two Vim sections?
ionling: Done.
And I put it in front of Vim because I prefer Emacs🤣

Patch:
diff --git a/README.md b/README.md
index 2700685..9c67d95 100644
--- a/README.md
+++ b/README.md
@@ -517,6 +517,15 @@ simply configure `gopls` to use `gofumpt`:
 call govim#config#Set("Gofumpt", 1)
 ```
 
+#### Emacs
+
+For [lsp-mode](https://emacs-lsp.github.io/lsp-mode/) users:
+
+```elisp
+(lsp-register-custom-settings
+ '(("gopls.gofumpt" t)))
+```
+
 #### Sublime Text
 
 With ST4, install the Sublime Text LSP extension according to [the documentation](https://github.com/sublimelsp/LSP),
diff --git a/gofmt.go b/gofmt.go
index 58a63e6..d7391bb 100644
--- a/gofmt.go
+++ b/gofmt.go
@@ -30,18 +30,22 @@ import (
 
 var (
 	// main operation modes
-	list      = flag.Bool("l", false, "list files whose formatting differs from gofumpt's")
-	write     = flag.Bool("w", false, "write result to (source) file instead of stdout")
-	doDiff    = flag.Bool("d", false, "display diffs instead of rewriting files")
-	allErrors = flag.Bool("e", false, "report all errors (not just the first 10 on different lines)")
+	list      = flag.Bool("l", false, "")
+	write     = flag.Bool("w", false, "")
+	doDiff    = flag.Bool("d", false, "")
+	allErrors = flag.Bool("e", false, "")
 
 	// debugging
-	cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file")
+	cpuprofile = flag.String("cpuprofile", "", "")
 
 	// gofumpt's own flags
-	langVersion = flag.String("lang", "", "target Go version in the form 1.X (default from go.mod)")
-	extraRules  = flag.Bool("extra", false, "enable extra rules which should be vetted by a human")
-	showVersion = flag.Bool("version", false, "show version and exit")
+	langVersion = flag.String("lang", "", "")
+	extraRules  = flag.Bool("extra", false, "")
+	showVersion = flag.Bool("version", false, "")
+
+	// DEPRECATED
+	rewriteRule = flag.String("r", "", "")
+	simplifyAST = flag.Bool("s", false, "")
 )
 
 // Keep these in sync with go/format/format.go.
@@ -71,8 +75,18 @@ func report(err error) {
 }
 
 func usage() {
-	fmt.Fprintf(os.Stderr, "usage: gofumpt [flags] [path ...]\n")
-	flag.PrintDefaults()
+	fmt.Fprintf(os.Stderr, `usage: gofumpt [flags] [path ...]
+	-version  show version and exit
+
+	-d        display diffs instead of rewriting files
+	-e        report all errors (not just the first 10 on different lines)
+	-l        list files whose formatting differs from gofumpt's
+	-w        write result to (source) file instead of stdout
+	-extra    enable extra rules which should be vetted by a human
+
+	-cpuprofile str    write cpu profile to this file
+	-lang       str    target Go version in the form 1.X (default from go.mod)
+`)
 }
 
 func initParserMode() {
@@ -204,6 +218,14 @@ func gofumptMain() {
 	flag.Usage = usage
 	flag.Parse()
 
+	if *simplifyAST {
+		fmt.Fprintf(os.Stderr, "warning: -s is deprecated as it is always enabled\n")
+	}
+	if *rewriteRule != "" {
+		fmt.Fprintf(os.Stderr, `the rewrite flag is no longer available; use "gofmt -r" instead`+"\n")
+		os.Exit(2)
+	}
+
 	// Print the gofumpt version if the user asks for it.
 	if *showVersion {
 		version.Print()


Test patch:
diff --git a/testdata/scripts/deprecated-flags.txt b/testdata/scripts/deprecated-flags.txt
new file mode 100644
index 0000000..0989b40
--- /dev/null
+++ b/testdata/scripts/deprecated-flags.txt
@@ -0,0 +1,26 @@
+cp foo.orig.go foo.go
+! gofumpt -w -r foo foo.go
+stderr 'the rewrite flag is no longer available; use "gofmt -r" instead\n'
+cmp foo.orig.go foo.go
+
+gofumpt -w -s foo.go
+stderr 'warning: -s is deprecated as it is always enabled\n'
+cmp foo.go foo.go.golden
+
+gofumpt -d foo.go.golden
+! stdout .
+
+-- foo.orig.go --
+package p
+
+func f() {
+
+	println("foo")
+
+}
+-- foo.go.golden --
+package p
+
+func f() {
+	println("foo")
+}