Automated code formatting keeps your code consistent and readable. It's also a great way to avoid arguments about code style (bikeshedding).
I almost never start a new project without enforcing automated code formatting.
For example, this is technically valid:
func main() {
fmt.Println("hello world!") }
But it's not formatted according to standard conventions. You would normally write it like this:
func main() {
fmt.Println("hello world!")
}
The go fmt command formats Go code. It's built into the Go toolchain, so you don't need to install anything additional to use it.
I have configured VS Code to auto-format my code on save, so my code is always formatted. The default "Notely" project should already be formatted properly, so let's break it so that we can see how go fmt works.
func main() {
vs
func main(){
Run and submit the CLI tests from the root of your repo.