Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RelatedInformation for analysis Diagnostic. #1773

Merged
merged 1 commit into from
Feb 24, 2021

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 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