Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fully format generated files if given explicitly
Otherwise it's very hard to apply gofumpt rules to generated code. It still makes sense to skip the added rules with "gofumpt -w .", because more often than not code generators only obey gofmt, and it's often unnecessary to force generated code to follow gofumpt. The behavior is similar to how we treat vendor directories, with the difference that we do fully skip vendor directories by default, whereas for generated Go files we still apply gofmt. The difference is that changing vendored files may upset cmd/go, and walking the vendor directory can unnecessarily waste time. While here, tweak the README to better explain these special cases. Fixes #180.
- Loading branch information
Showing
4 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
cp foo.go foo.go.orig | ||
cp foo.go foo.go.golden | ||
exec gofmt -w foo.go.golden | ||
gofumpt foo.go | ||
cmp stdout foo.go.golden | ||
|
||
gofumpt -w foo.go | ||
cmp foo.go foo.go.golden | ||
|
||
cp foo.go.orig foo.go | ||
gofumpt -w . | ||
cmp foo.go foo.go.golden | ||
gofumpt -l . | ||
! stdout . | ||
! stderr . | ||
|
||
-- foo.go -- | ||
// foo is a package about bar. | ||
|
||
// Code generated by foo. DO NOT EDIT. | ||
// versions: | ||
// foo v1.26.0 | ||
|
||
package foo | ||
|
||
type i interface { | ||
func f() { | ||
|
||
println("body") | ||
|
||
} | ||
-- foo.go.golden -- | ||
// foo is a package about bar. | ||
|
||
a(x int) int | ||
// Code generated by foo. DO NOT EDIT. | ||
|
||
b(x int) int | ||
package foo | ||
|
||
c(x int) int | ||
func f() { | ||
println("body") | ||
} |