--- title: "Checks" description: "Explanations for all checks in Staticcheck" menu: main: weight: 2 pre: --- {{< all-checks.inline >}} {{ define "category-list" }} {{ range $name := index $.p.Site.Data.checks.ByCategory $.cat }} {{ $check := index $.p.Site.Data.checks.Checks $name }} {{ $name }} {{ $check.TitleMarkdown | markdownify }} {{ end }} {{ end }} {{ define "category" }} {{ range $name := index $.p.Site.Data.checks.ByCategory .cat }} {{ $check := index $.p.Site.Data.checks.Checks $name }}

{{ $name }} - {{ $check.TitleMarkdown | markdownify }}{{ if $check.NonDefault }} non-default{{ end }}

{{ $check.TextMarkdown | $.p.Page.RenderString (dict "display" "block") }} {{ if $check.Before }}

Before:

{{ highlight $check.Before "go" "" }} {{ end }} {{ if $check.After }}

After:

{{ highlight $check.After "go" "" }} {{ end }}
Available since
{{ $check.Since }}
{{ if $check.Options }}
Options
{{ end }}
{{ end }} {{ end }} {{ $categoryNames := slice "SA" "SA1" "SA2" "SA3" "SA4" "SA5" "SA6" "SA9" "S" "S1" "ST" "ST1" "QF" "QF1" }} {{ $categories := dict "SA" (dict "name" "SA" "title" "staticcheck") "SA1" (dict "name" "SA1" "title" "Various misuses of the standard library") "SA2" (dict "name" "SA2" "title" "Concurrency issues") "SA3" (dict "name" "SA3" "title" "Testing issues") "SA4" (dict "name" "SA4" "title" "Code that isn't really doing anything") "SA5" (dict "name" "SA5" "title" "Correctness issues") "SA6" (dict "name" "SA6" "title" "Performance issues") "SA9" (dict "name" "SA9" "title" "Dubious code constructs that have a high probability of being wrong") "S" (dict "name" "S" "title" "simple") "S1" (dict "name" "S1" "title" "Code simplifications") "ST" (dict "name" "ST" "title" "stylecheck") "ST1" (dict "name" "ST1" "title" "Stylistic issues") "QF" (dict "name" "QF" "title" "quickfix") "QF1" (dict "name" "QF1" "title" "Quickfixes") }} {{ range $name := $categoryNames }} {{ $cat := index $categories $name }} {{ template "category-list" (dict "p" $ "cat" $cat.name) }} {{ end }}
Check Short description
{{ $cat.name }}{{ $cat.title }}
{{ define "category-header" }}

{{ .name }} – {{ .title }}

{{ end }} {{ define "subcategory-header" }}

{{ .name }} – {{ .title }}

{{ end }} {{ template "category-header" (index $categories "SA") }}

The SA category of checks, codenamed staticcheck, contains all checks that are concerned with the correctness of code.

{{ template "subcategory-header" (index $categories "SA1") }}

Checks in this category deal with misuses of the standard library. This tends to involve incorrect function arguments or violating other invariants laid out by the standard library's documentation.

{{ template "category" (dict "p" $ "cat" "SA1") }} {{ template "subcategory-header" (index $categories "SA2") }}

Checks in this category find concurrency bugs.

{{ template "category" (dict "p" $ "cat" "SA2") }} {{ template "subcategory-header" (index $categories "SA3") }}

Checks in this category find issues in tests and benchmarks.

{{ template "category" (dict "p" $ "cat" "SA3") }} {{ template "subcategory-header" (index $categories "SA4") }}

Checks in this category point out code that doesn't have any meaningful effect on a program's execution. Usually this means that the programmer thought the code would do one thing while in reality it does something else.

{{ template "category" (dict "p" $ "cat" "SA4") }} {{ template "subcategory-header" (index $categories "SA5") }}

Checks in this category find assorted bugs and crashes.

{{ template "category" (dict "p" $ "cat" "SA5") }} {{ template "subcategory-header" (index $categories "SA6") }}

Checks in this category find code that can be trivially made faster.

{{ template "category" (dict "p" $ "cat" "SA6") }} {{ template "subcategory-header" (index $categories "SA9") }}

Checks in this category find code that is probably wrong. Unlike checks in the other SA categories, checks in SA9 have a slight chance of reporting false positives. However, even false positives will point at code that is confusing and that should probably be refactored.

{{ template "category" (dict "p" $ "cat" "SA9") }} {{ template "category-header" (index $categories "S") }}

The S category of checks, codenamed simple, contains all checks that are concerned with simplifying code.

{{ template "subcategory-header" (index $categories "S1") }}

Checks in this category find code that is unnecessarily complex and that can be trivially simplified.

{{ template "category" (dict "p" $ "cat" "S1") }} {{ template "category-header" (index $categories "ST") }}

The ST category of checks, codenamed stylecheck, contains all checks that are concerned with stylistic issues.

{{ template "subcategory-header" (index $categories "ST1") }}

The rules contained in this category are primarily derived from the Go wiki and represent community consensus.

Some checks are very pedantic and disabled by default. You may want to tweak which checks from this category run, based on your project's needs.

{{ template "category" (dict "p" $ "cat" "ST1") }} {{ template "category-header" (index $categories "QF") }}

The QF category of checks, codenamed quickfix, contains checks that are used as part of gopls for automatic refactorings. In the context of gopls, diagnostics of these checks will usually show up as hints, sometimes as information-level diagnostics.

{{ template "subcategory-header" (index $categories "QF1") }} {{ template "category" (dict "p" $ "cat" "QF1") }} {{< /all-checks.inline >}}