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
{{ message }}
Repository navigation
staticcheck feature request: add check when user try to modify global variable on other package #1152
I would love to have this check, but it probably will only be included as an aggresive check, not as a standard one. Some people choose to modify “foreign globals” in tests or, in case with net/http, to change the settings of the default clients.
This can at best be an aggressive check, for the reasons Ainar already mentioned. Expanding on that, it's not correct to say that no foreign globals should ever be assigned to, nor that it cannot be done correctly.
I am, however, not sure how useful this check would be in the aggressive category. It seems unlikely to me that someone would assign to a global by accident.
Maybe implementing a subset of this for assigning to an error type would be less agressive? And even less agressive would be implementing this only for standard library errors.
Activity
ainar-g commentedon Dec 28, 2021
I would love to have this check, but it probably will only be included as an
aggresivecheck, not as a standard one. Some people choose to modify “foreign globals” in tests or, in case withnet/http, to change the settings of the default clients.dominikh commentedon Jan 7, 2022
This can at best be an
aggressivecheck, for the reasons Ainar already mentioned. Expanding on that, it's not correct to say that no foreign globals should ever be assigned to, nor that it cannot be done correctly.I am, however, not sure how useful this check would be in the
aggressivecategory. It seems unlikely to me that someone would assign to a global by accident.soypat commentedon Jul 2, 2023
Maybe implementing a subset of this for assigning to an
errortype would be less agressive? And even less agressive would be implementing this only for standard library errors.