Go fmt: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
=Overview= | =Overview= | ||
<code>gofmt</code> is a program that operates at source file level. | |||
<code>go fmt</code> delegates to <code>gofmt</code>, and it is equivalent to: | <code>go fmt</code> operates at package level rather than source file level. <code>go fmt</code> delegates to <code>gofmt</code>, and it is equivalent to: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
Line 16: | Line 16: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
One counterintuitive fact is that it uses the tab character for indentation. This is uncommon. | Both tools format source code files, by applying a predetermined layout, which includes a standard style of indentation and vertical alignment, and retains and if necessary reformats comments. One counterintuitive fact is that it uses the tab character for indentation. This is uncommon. | ||
Rob Pike: "[https://www.youtube.com/watch?v=PAAkCSZUG1c&t=523s gofmt style is no one's favorite, yet gofmt is everyone's favorite]". | Rob Pike: "[https://www.youtube.com/watch?v=PAAkCSZUG1c&t=523s gofmt style is no one's favorite, yet gofmt is everyone's favorite]". |
Revision as of 23:22, 2 July 2024
External
Internal
Overview
gofmt
is a program that operates at source file level.
go fmt
operates at package level rather than source file level. go fmt
delegates to gofmt
, and it is equivalent to:
gofmt -l -w <file>
Both tools format source code files, by applying a predetermined layout, which includes a standard style of indentation and vertical alignment, and retains and if necessary reformats comments. One counterintuitive fact is that it uses the tab character for indentation. This is uncommon.
Rob Pike: "gofmt style is no one's favorite, yet gofmt is everyone's favorite".