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
Is there a way how to match only method call and not every identifier with the same name?
We have code like this below. On Identifier structure we define ID function, which we should use always. And GID which is more like a helper, which we can use only in Tests, so it can panic easily.
I wanted to use forbidigo to match all usage of GID() outside *_test.go files, but I wasn't successful.
constGID="gid:"typeURIGidIdentifierstruct {
GIDstring`uri:"gid" binding:"required,gid"`
}
typeIdentifierstruct {
// ...
}
func (x*Identifier) GID() string {
gid, err:=x.ID()
iferr!=nil {
panic("use ID() to check error")
}
returngid
}
func (x*Identifier) ID() (string, error) {
// ...return"", nil
}
funcxx() {
a:= (&Identifier{}).GID() // this is only point, where forbidigo should complain.
}
First try
I'm using GolangCI linter and if I added this, it was complaining about GID constant and GID field in URIGidIdentifier too. And also during GID() declaration.
forbidigo:
forbid:
- p: ^GID$msg: Use ID() instead
Second try
I tried to check the function call like this, having escaped () in the regex, but now it is matching nothing. Nor false positives as above, nor valid ocurrences.
forbidigo:
forbid:
- p: ^GID\(\)$msg: Use ID() instead
Is there a way how to make this works?
The text was updated successfully, but these errors were encountered:
I feel like the constant declaration and name probably shouldn't be matched, so that is arguably a bug. For now, you could consider using nolint for those lines (although maybe this becomes moot when you add the type prefix).
Is there a way how to match only method call and not every identifier with the same name?
We have code like this below. On Identifier structure we define
ID
function, which we should use always. AndGID
which is more like a helper, which we can use only in Tests, so it canpanic
easily.I wanted to use forbidigo to match all usage of
GID()
outside*_test.go
files, but I wasn't successful.First try
I'm using GolangCI linter and if I added this, it was complaining about
GID
constant andGID
field inURIGidIdentifier
too. And also during GID() declaration.Second try
I tried to check the function call like this, having escaped
()
in the regex, but now it is matching nothing. Nor false positives as above, nor valid ocurrences.Is there a way how to make this works?
The text was updated successfully, but these errors were encountered: