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
First, thank you for providing this linter! I am using it as part of golangci-lint. I am now working on a project that have some regex.Must in global variables and have noticed that these are excluded from linter when used as global variables.
I assume that is because they are in this case compile-time errors if something goes wrong.
Now I also need to do same thing with templates for policy documents which are part of HTTP request body. Template documents are defined as consts and in global variable I am doing following:
which if anything is wrong with AdminPolicy template document or ReaderPolicy template document are compiler-ime errors, same as for regex. Therefore I think it would be nice to have same exception for template.Must as we have for regex.Must.
I'm on the fence on this one. I have seen this be a somewhat common pattern to store these values in global variables, but it continues to perpetuate the idea of using global variables. I don't use templates a whole lot myself though, are there ways that aren't obtuse to using them without globals?
Not sure I understand what you mean. There are always ways around it, but they would be consts if they could 😉, so the next best thing is global variables. They never change in my package and are the same use case as the regex. Right now, I am disabling your linter for those lines, but I see no harm in allowing them by default as regex-es are.
Activity
zemanlx commentedon Mar 3, 2022
@leighmcculloch I can also do the PR if you agree that it is a good idea.
leighmcculloch commentedon Jan 15, 2023
I'm on the fence on this one. I have seen this be a somewhat common pattern to store these values in global variables, but it continues to perpetuate the idea of using global variables. I don't use templates a whole lot myself though, are there ways that aren't obtuse to using them without globals?
zemanlx commentedon Jan 16, 2023
Not sure I understand what you mean. There are always ways around it, but they would be
consts if they could 😉, so the next best thing is global variables. They never change in my package and are the same use case as the regex. Right now, I am disabling your linter for those lines, but I see no harm in allowing them by default as regex-es are.