-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add ExcludeMethod options with default #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The signatures of the SQL elements seem too "generic" ( I understand you are trying to create something strict and configurable, but I think the full signature approach is a bit overkill, at least as a first step. For me, the option is a bit weird: either it is an exception, then it can be managed with the exclusions inside golangci-lint, or this a common interface, and then it should be integrated internally (if possible). Also, the option can lead to false negatives: a signature can be the same between different methods but those methods are related to different structures. For me, the first step could be to not provide options, and filter on method names only. names := []string{
"MarshalText",
"MarshalJSON",
"MarshalXML",
"MarshalYAML",
"MarshalBinary",
"GobEncode",
}
for _, name := range names {
if funcDecl.Name.Name == name {
return
}
} This will reduce the majority of false positives, and for the other cases, classic exclusions for the type inside golangci-lint can be enough. issues:
exclude-rules:
- path: myfile.go
text: 'the methods of "Foo" use pointer receiver and non-pointer receiver.'
linters:
- recvcheck If you want to add an option, I think something simple can be used: struct name + method name (ex: typeName := recvTypeName(funcDecl.Recv.List[0].Type) func recvTypeName(r ast.Expr) string {
switch n := r.(type) {
case *ast.Ident:
return n.Name
case *ast.StarExpr:
return recvTypeName(n.X)
}
return ""
} It's also possible to create a mix of solutions:
WDYT? |
@ldez I agree that checking the method signature is somewhat overkill for most users. The idea of struct name and method name configuration is a good one. It’s much more usable than the full signature approach. (Maybe we can add this to the next PR.) I’ll fix this PR with the following changes:
|
- Remove Value function from list, to general - Remove ExcludeMethod option for now
Applied review in b0ba9d3 |
@ldez |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changed
UnmarshalJSON(data []byte, v any) error
Considerations
next todos
Fixes #7