We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Linting Review

"Linting" can be such a vague and confusing term. I want to go over a few of the most common and useful checks that staticcheck lints for, just so you can see a few more examples.

If you're curious, you can see the full list of checks here.

Unused Variables (U1000)

This is the one we've been using so far. It checks for unused variables, functions, and types.

Invalid Printf Call (SA5009)

This one is pretty self-explanatory. It checks for invalid Printf calls. For example, if you try to print a string with a %d format specifier, you'll get an error.

“Defer” in Range Loops (SA9001)

Defers in range loops may not run when you expect them to, and in general you should just avoid them.

Replace for Loops With Call to Copy (S1001)

Before:

for i, x := range src {
    dst[i] = x
}

After:

copy(dst, src)