如何使用重写规则在 gofmt 工具中用空格替换制表符?
How to use rewrite rule to replace tabs with spaces in gofmt tool?
gofmt
命令支持 -r 标志以在格式化代码期间使用重写规则。如何使用它用 空格缩进 ?
替换 制表符缩进
Go 的格式被 gofmt
强制要求使用制表符缩进。
另见导致它的决定:
https://code.google.com/p/go/issues/detail?id=7101
The rewrite rule specified with the -r flag must be a string of the
form:
pattern -> replacement
Both pattern and replacement must be valid Go expressions.
制表符和 space 字符不是有效的 Go 表达式。不行。
The Go Programming Language
Alan A. A. Donovan & Brian W. Kernighan
ISBN: 978-0134190440
Go takes a strong stance on code formatting. The gofmt tool rewrites
code into the standard format, and the go tool’s fmt subcommand
applies gofmt to all the files in the specified package, or the ones
in the current directory by default. All Go source files in the book
have been run through gofmt, and you should get into the habit of
doing the same for your own code. Declaring a standard format by fiat
eliminates a lot of pointless debate about trivia and, more
importantly, enables a variety of automated source code
transformations that would be infeasible if arbitrary formatting were
allowed.
始终使用 gofmt 代码格式。
gofmt
命令支持 -r 标志以在格式化代码期间使用重写规则。如何使用它用 空格缩进 ?
Go 的格式被 gofmt
强制要求使用制表符缩进。
另见导致它的决定:
https://code.google.com/p/go/issues/detail?id=7101
The rewrite rule specified with the -r flag must be a string of the form:
pattern -> replacement
Both pattern and replacement must be valid Go expressions.
制表符和 space 字符不是有效的 Go 表达式。不行。
The Go Programming Language
Alan A. A. Donovan & Brian W. Kernighan
ISBN: 978-0134190440
Go takes a strong stance on code formatting. The gofmt tool rewrites code into the standard format, and the go tool’s fmt subcommand applies gofmt to all the files in the specified package, or the ones in the current directory by default. All Go source files in the book have been run through gofmt, and you should get into the habit of doing the same for your own code. Declaring a standard format by fiat eliminates a lot of pointless debate about trivia and, more importantly, enables a variety of automated source code transformations that would be infeasible if arbitrary formatting were allowed.
始终使用 gofmt 代码格式。