-
Notifications
You must be signed in to change notification settings - Fork 284
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
Allow use of _xxx
with unused-parameter
rule
#613
Comments
Hi @Gusted thanks for filling the issue.
It is common in JS but not in GO, to the point that |
I see, fair point. Thank you for your response. |
Is it out of question to have a rule configuration option for this? It could allow the user to define a regex pattern. The default pattern could be |
Not at all. My intention with the previous comment was to highlight that prefixing identifiers with
Yes, it is something that could be studied |
Prefixing with
(I have to disable structcheck and unused for this in golangci-lint) |
@silverwind thanks for joining to the discussion could you provide more details about the use of
Do you mean type something struct {
signo int32
} and type something struct {
_signo int32
}
I know that adding a blank field is a hack to force you to use field names when instantiating a struct (https://go.dev/play/p/hJeg6a0D_x9)
What do you mean by pad the struct and how |
|
Can't really comment much on golang practices, but I'm using the Eslint has distinct pattern configuration for various types of variables (primarly arguments and regular variables), maybe this is something to consider to split into multiple options too. |
I've not see allwedRegex argumnet in |
Think same is for unused-receiver |
Provided MR for this feature |
Closed by #858 |
The discussion was quite long, the fix is great. But I think it would be interesting if the use case could be explained in more details. I mean the _ prefix is pretty strange. After reading the discussion, I'm still unsure if _ prefix has a consequence on exportability in Go @silverwind talked about it to replicate a pattern used in JavaScript I'm still unsure what was the whole purpose of the feature/issue it try to solve |
Salut @ccoVeille, The func (b *footnoteBlockParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) into func (b *footnoteBlockParser) Continue(_ ast.Node, reader text.Reader, _ parser.Context) leads to less understandable code than func (b *footnoteBlockParser) Continue(_node ast.Node, reader text.Reader, _pc parser.Context) IMO (check my comments in this thread) using the prefix is not necessary/useful. |
Thanks @chavacava it's way clearer now. And I agree with you. Also, I would expect Go to use memory when passing such argument while it won't with But I understand the logic of saying that an interface passing two strings as argument that is not used look a bit odd func (c *Whatever) Format (_ string, _ string) string {
return "whatever"
} But I would prefer to keep this syntax than having func (c *Whatever) Format (_fmt string, _arg string) string {
return "whatever"
} |
While I still agree that type Name = string
type Arg = string
func Format (_ Name, _ Arg) string {
return "whatever"
} |
That's right |
There is also https://github.com/mvdan/unparam which by default ignores |
Is your feature request related to a problem? Please describe.
We're enabling the
unused-parameter
rule on our repo to detect if there are possible bugs. A lot of parameters can be changed to_
, but in certain cases it will make the code more unreadableDescribe the solution you'd like
Add a option(or by default) that certain use-case are allowed, this can be limited to just the
_
prefix or a generic regex option. Using the_
prefix is common in JS to still have the variable name but show that the variable is unused.Describe alternatives you've considered
Adding the
//revive:disable...
comment, but that's better to avoided for each function that needs this.Additional context
None
The text was updated successfully, but these errors were encountered: