Skip to content
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

Params is a keyword? #111

Open
flyinprogrammer opened this issue Nov 21, 2020 · 1 comment
Open

Params is a keyword? #111

flyinprogrammer opened this issue Nov 21, 2020 · 1 comment

Comments

@flyinprogrammer
Copy link

Context:

So I've stumbled upon needing to use this project while trying to resurrect the wildly out of date / broken slack client in Atlantis: https://github.com/runatlantis/atlantis/tree/master/server/events/webhooks

I'm not sure how much anyone cares about any of these rambles, but this community seems like they might care? So here we are.


So the first discovery I've found is trivial, defining an interface's method with a parameter named params makes our generator create broken code:

https://github.com/flyinprogrammer/pegomock_examples/blob/issues/params_keyword/slack.go#L8

https://github.com/flyinprogrammer/pegomock_examples/blob/issues/params_keyword/mocks/mock_slack_client.go#L32

The solution is to simply ignore the provided name params:

https://github.com/slack-go/slack/blob/master/conversation.go#L81

And do something like this:

https://github.com/flyinprogrammer/pegomock_examples/blob/workaround/params_keyword/slack.go#L8

https://github.com/flyinprogrammer/pegomock_examples/blob/workaround/params_keyword/mocks/mock_slack_client.go#L32

And we're off again.

sloth_smile

Not sure if we want to document this hiccup, or make our code generator smarter? Happy to contribute, just need some guidance.

@petergtz
Copy link
Owner

Hey @flyinprogrammer, thanks for reporting this and of course for the magnificent sloth there :-).

I think we should definitely make the code generator smarter here. Seems like the simplest would be to prefix or suffix the local variable names with _ or even __. These are against Go naming conventions (for normal code, but not generated one) and should make sure, we don't get this hiccup. I think that's not too difficult and would not require people to read through framework caveats.

I'd be very happy to merge that PR, if you decide to contribute.

Thank you,
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants