Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

false positive #6

Closed
jacobbogdanov opened this issue Feb 2, 2021 · 5 comments
Closed

false positive #6

jacobbogdanov opened this issue Feb 2, 2021 · 5 comments

Comments

@jacobbogdanov
Copy link

the following code

package main

import (
	"context"
	"fmt"
)

func main() {

	ctx := context.Background()
	value := ctx.Value("key")
	if value == nil {
		panic("")
	}

	fmt.Println(value.(string))
}

produces this error (when running through golangci-lint version 1.36.0);

test.go:11:2: variable 'value' is only used in the if-statement (test.go:12:2); consider using short syntax (ifshort)
        value := ctx.Value("key")
@AlekSi
Copy link

AlekSi commented Feb 3, 2021

I have a similar case:

ch := c.responses[id]
if ch == nil {
   c.m.Unlock()
   c.close(errors.WithStack(fmt.Errorf("no subscriber for ID %d", id)))
   return
}

delete(c.responses, id)
c.m.Unlock()
ch <- resp

@jacobbogdanov
Copy link
Author

and I think I found another one;

package main

import "fmt"

func main() {
	name := "Jacob"

	_ = "random data" + name // <- this usage is not being seen

	if false {
		fmt.Printf("my name is %s", name)
	}
}

produces this error (when running through golangci-lint version 1.36.0);

main.go:6:2: variable 'name' is only used in the if-statement (main.go:10:2); consider using short syntax (ifshort)
        name := "Jacob"

esimonov added a commit that referenced this issue Feb 6, 2021
@esimonov
Copy link
Owner

esimonov commented Feb 6, 2021

Thanks for your interest!

@jacobbogdanov The first false positive you reported has already been fixed (113a74d) and released in version 1.0.1. Please stay tuned for golanci-lint 1.36.1.
The second one, together with the one reported by @AlekSi , is fixed in 0ee1452.

@jpreese
Copy link

jpreese commented Feb 18, 2021

Just ran into the second case as well. Thanks for the fix! Hope to see it added to golanglinter soon 😄

@esimonov
Copy link
Owner

Sorry for not releasing it for so long. v1.0.2 is out and merged into golanci-lint. Stay tuned for its new release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants