Introduction to Staticcheck 2020.1

Staticcheck 2020.1 introduces UI improvements, speed enhancements, and a number of new as well as improved checks. Additionally, it is the first release to support the upcoming Go 1.14.

UI improvements

We've improved the output of the staticcheck command as well as Staticcheck's integration with gopls to make it easier to understand the problems that are being reported.

Related information describes the source of a problem, or why Staticcheck believes that there is a problem. Take the following piece of code for example:

func fn(x *int) {
	if x == nil {
		log.Println("x is nil, returning")
	}
	// lots of code here
	log.Println(*x)
}

Staticcheck 2020.1 will produce the following output:

foo.go:6:14: possible nil pointer dereference (SA5011)
	foo.go:2:5: this check suggests that the pointer can be nil

The actual problem that is being reported is the "possible nil pointer dereference". Staticcheck also explains why it believes that x might be nil, namely the comparison on line 2.

When using the text or stylish formatters, related information will appear as indented lines. The json formatter adds a new field related to problems, containing position information as well as the message. Editors that use gopls will also display the related information.

Related information should make it easier to understand why Staticcheck is flagging code, and how to fix problems.

Integration with gopls has seen some other improvements as well¹. We now emit better position information that more accurately reflects the true source of a problem. The most obvious example is that a missing package comment will no longer underline the entire file. Similarly, invalid function arguments will be highlighted individually, instead of highlighting the call as a whole. Finally, some problems can now be automatically fixed by using quick fixes.

¹: due to the nature of Staticcheck's integration with gopls, gopls will need to update their dependency on Staticcheck before benefiting from these changes.

Better caching

The 2019.2 release introduced caching to Staticcheck, greatly speeding up repeated runs. However, the caching only applied to dependencies; the packages under analysis still had to be analyzed anew on every invocation to compute the list of problems. Staticcheck 2020.1 introduces caching of problems found, so that repeat runs for unchanged packages are virtually instantaneous.

Checks

New checks

Numerous new checks have been added in this release:

{{ check "ST1020" }}, {{ check "ST1021" }} and {{ check "ST1022" }} are not enabled by default.

Changed checks

Several checks have been improved:

General bug fixes

The following bugs were fixed:

Staticcheck 2020.1.1 release notes

The 2020.1 release neglected to update the version string stored in the binary, causing staticcheck -version to incorrectly emit (no version).

Staticcheck 2020.1.2 release notes

The 2020.1.1 release incorrectly identified itself as version 2020.1.

Staticcheck 2020.1.3 release notes

This release fixes two bugs involving //lint:ignore directives:

Staticcheck 2020.1.4 release notes

This release adds special handling for imports of the deprecated github.com/golang/protobuf/proto package.

github.com/golang/protobuf has deprecated the proto package, but their protoc-gen-go still imports the package and uses one of its constants, to enforce a weak dependency on a sufficiently new version of the legacy package.

Staticcheck would flag the import of this deprecated package in all code generated by protoc-gen-go. Instead of forcing the project to change their project structure, we choose to ignore such imports in code generated by protoc-gen-go. The import still gets flagged in code not generated by protoc-gen-go.

You can find more information about this in the upstream issue.

Staticcheck 2020.1.5 release notes

This release fixes a crash in the pattern matching engine and a false positive in SA4006.