gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
390 stars 22 forks source link

What is causing this ineffassign? #66

Closed TomWright closed 2 years ago

TomWright commented 2 years ago

Hi there,

I can see in my goreportcard result that I have an ineffassign: https://goreportcard.com/report/github.com/TomWright/dasel

It's highlighting line 281 (line 2 in this snippet):

cmd.AddCommand(
    putStringCommand(),
    putBoolCommand(),
    putIntCommand(),
    putObjectCommand(),
    putDocumentCommand(),
)

From the README:

An assignment is ineffectual if the variable assigned is not thereafter used.

I don't understand why this line has been highlighted since:

  1. No variable is assigned on that line
  2. The return value is passed straight into a func where it is immediately used

Have I missed something or would this be considered a bug?

gordonklaus commented 2 years ago

Looking closer at the goreportcard result, it says: Line 281: warning: undeclared name: putStringCommand (ineffassign)

This isn't an ineffectual assignment, but an error loading the code.

When I clone your repository and run ineffassign ./..., I get no errors. So, this error must be a result of the way goreportcard runs the tool. I see that it uses gometalinter, which is deprecated, FWIW.

I can sort of reproduce the error by running ineffassign internal/command/put.go, but then, of course, I get undeclared name errors for all of the put*Command functions. Perhaps goreportcard/gometalinter is truncating its output to only show the first couple of errors (but why the duplicate)?

Anyway, I suggest you take this up with the folks at goreportcard.

TomWright commented 2 years ago

Thanks for the quick reply and clear explanation 👍