

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 2
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Code Formatting deals with the aesthetic appearance of the code. For example, it enforces things like whitespace, indentation, and line length.
On the other hand, linting has more to do with the analysis of code to detect functional issues. Linters provide warnings or errors for potentially problematic code.
Personally I use staticcheck for linting in Go. It has a lot of useful checks with sane defaults, and it's easy to configure. As far as I can tell it's essentially replaced golint as the most popular linter for Go.
To install staticcheck, run:
go install honnef.co/go/tools/cmd/staticcheck@latest
If you're on Mac and already have Homebrew, you may run:
brew install staticcheck
To run staticcheck on the entire Notely codebase, run this from the root of the project:
staticcheck ./...
If you get a command not found error, your GOPATH may not be in your PATH. Run the following and use the appropriate config file name for your shell.
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
It should run without errors because the project is already configured to pass all of the default checks. Let's make sure that's true by breaking something!
Add an unused function to the main.go file:
func unused() {
// this function does nothing
// and is called nowhere
}
If you're using VS Code with the official Go extension and the gopls language server, static check should automatically detect the error and underline the function name. You can also run staticcheck manually from the CLI:
staticcheck ./...
You should see an error like this:
func unused is unused (U1000)
If so, great! Staticcheck is working properly.
Become a member to Complete