Skip to content

Commit

Permalink
gofumpt -s no longer works
Browse files Browse the repository at this point in the history
closes mvdan#174
  • Loading branch information
Oiyoo committed Dec 6, 2021
1 parent 872763c commit 673aeb2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var (
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")

// DEPRECATED
rewriteRule = flag.String("r", "", "DEPRECATED: you can use gofmt for it instead")
simplifyAST = flag.Bool("s", false, "DEPRECATED: the simplify flag is enabled by default")
)

// Keep these in sync with go/format/format.go.
Expand Down Expand Up @@ -75,6 +79,16 @@ func usage() {
flag.PrintDefaults()
}

func checkDeprecated() {
if *simplifyAST {
fmt.Fprintf(os.Stderr, "warning: -s used, the simplify flag is enabled by default\n")
}
if *rewriteRule != "" {
fmt.Fprintf(os.Stderr, "the rewrite flag is no longer available, you can use gofmt for it instead\n")
os.Exit(2)
}
}

func initParserMode() {
parserMode = parser.ParseComments
if *allErrors {
Expand Down Expand Up @@ -204,6 +218,8 @@ func gofumptMain() {
flag.Usage = usage
flag.Parse()

checkDeprecated()

// Print the gofumpt version if the user asks for it.
if *showVersion {
version.Print()
Expand Down
13 changes: 13 additions & 0 deletions testdata/scripts/deprecated-rewrite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cp foo.orig.go foo.go
! gofumpt -w -r foo foo.go
stderr 'the rewrite flag is no longer available, you can use gofmt for it instead\n'
cmp foo.orig.go foo.go

-- foo.orig.go --
package p

func f() {

println("foo")

}
20 changes: 20 additions & 0 deletions testdata/scripts/deprecated-simplify.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
gofumpt -w -s foo.go
cmp foo.go foo.go.golden

gofumpt -d foo.go.golden
! stdout .

-- foo.go --
package p

func f() {

println("foo")

}
-- foo.go.golden --
package p

func f() {
println("foo")
}

0 comments on commit 673aeb2

Please sign in to comment.