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

False positive U1000? #1372

Closed
MaximMolchanov opened this issue Feb 20, 2023 · 2 comments
Closed

False positive U1000? #1372

MaximMolchanov opened this issue Feb 20, 2023 · 2 comments

Comments

@MaximMolchanov
Copy link

Let's say we have two files:

package main

func foo() int {
	return 0
}

func main() {
}

and

//go:build sometag

package main

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestFoo(t *testing.T) {
	assert.Equal(t, 0, foo())
}

Is foo() unused?

$ staticcheck -f binary > tmp1
$ staticcheck -tags=sometag -f binary > tmp2
$ staticcheck -merge tmp1 tmp2
main.go:3:6: func foo is unused (U1000)

But is it?

We can move foo() to the second file, but is it correct to mark it as unused in such case? If yes, then why do we need merge at all?

@MaximMolchanov MaximMolchanov added false-positive needs-triage Newly filed issue that needs triage labels Feb 20, 2023
@MaximMolchanov
Copy link
Author

Anyway if we say that if function is used only in tests is still unused, then without tag:

package main

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestFoo(t *testing.T) {
	assert.Equal(t, 0, foo())
}

It also should be unused, right? But it is not:

$ staticcheck 
$ 

@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Feb 25, 2023
@dominikh
Copy link
Owner

dominikh commented Feb 25, 2023

I'll have to investigate this. At first glance the observed behavior in your first comment seems incorrect.

dominikh added a commit that referenced this issue Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants