You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have seen quite a few times that struct fields that previously were used in multiple places end up being used like local variables in methods after some kind of refactor. It is even easier to run into this problem when you have a large code base (or a struct with many fields or many methods) so you can't see all places that the variable is used in.
Let's say in the code example below that we used to have to keep track of our position inside the struct but we clean up the code and grab out position from somewhere else (think like position of window from OS) so we no longer need to keep it inside the struct. Our old pos() method (not changed since the other code was modified) still set the x and y fields even though they are never accessed anywhere else. It seems wrong to me.
I believe that staticcheck ought to flag this kind of problem. The x and y fields should be removed. Introducing this kind of check is not something that personally don't see introducing any more false positives than the already existing check for unused code.
I have seen quite a few times that struct fields that previously were used in multiple places end up being used like local variables in methods after some kind of refactor. It is even easier to run into this problem when you have a large code base (or a struct with many fields or many methods) so you can't see all places that the variable is used in.
Let's say in the code example below that we used to have to keep track of our position inside the struct but we clean up the code and grab out position from somewhere else (think like position of window from OS) so we no longer need to keep it inside the struct. Our old
pos()
method (not changed since the other code was modified) still set the x and y fields even though they are never accessed anywhere else. It seems wrong to me.I believe that staticcheck ought to flag this kind of problem. The x and y fields should be removed. Introducing this kind of check is not something that personally don't see introducing any more false positives than the already existing check for unused code.
The text was updated successfully, but these errors were encountered: