Skip to content

Conversation

@ldez
Copy link
Member

@ldez ldez commented Feb 24, 2021

Closes #1189

RelatedInformation is an experimental field from analysis Diagnostic structure.

https://github.com/golang/tools/blob/b4639ccb830b1c9602f1c96eba624bbbe20650ea/go/analysis/diagnostic.go#L30-L31

The implementation adds this information as a new issue.

According to my research, only Staticcheck uses this field.

Example

package example

func fn(x *byte) {
	println(*x)
	if x != nil {
		return
	}
}

Before:

$ golangci-lint run
main.go:3:6: `fn` is unused (deadcode)
func fn(x *byte) {
     ^
main.go:4:10: SA5011: possible nil pointer dereference (staticcheck)
        println(*x)
                ^

After:

$ ./golangci-lint run
main.go:3:6: `fn` is unused (deadcode)
func fn(x *byte) {
     ^
main.go:4:10: SA5011: possible nil pointer dereference (staticcheck)
        println(*x)
                ^
main.go:5:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
        if x != nil {
           ^

@ldez ldez added the enhancement New feature or improvement label Feb 24, 2021
@ldez ldez force-pushed the feat/related-information branch from f1a3e2f to 9462293 Compare February 24, 2021 00:35
@ldez ldez changed the title Support RelatedInformation analysis. Support RelatedInformation for analysis Diagnostic. Feb 24, 2021
@ldez ldez merged commit 856ffd1 into golangci:master Feb 24, 2021
@ldez ldez deleted the feat/related-information branch February 24, 2021 08:08
This was referenced Mar 7, 2021
@ldez ldez added this to the v1.38 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golangci-lint doesn't seem to make use of RelatedInformation

2 participants