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

fix: enforce-repeated-arg-type-style rule finds false positives in case of invalid types #1046

Merged

Conversation

denisvmedia
Copy link
Collaborator

closes #1032

@zak-pawel
Copy link

@denisvmedia Thanks! I tested code from this PR and it fixes most of the cases.

However, it still sees a problem for such cases (for op):

func printConfig(name string, p telegraf.PluginDescriber, op string, commented bool, di telegraf.DeprecationInfo, outputBuffer io.Writer) {

But when I change the second argument from telegraf.PluginDescriber to int, the function stops being problematic:

func printConfig(name string, p int, op string, commented bool, di telegraf.DeprecationInfo, outputBuffer io.Writer) {

There is a similar problem with return types.

@denisvmedia
Copy link
Collaborator Author

Yeah, that was my oversight. I will fix it. Thanks!

@denisvmedia
Copy link
Collaborator Author

@zak-pawel does it work for you now?

Copy link

@zak-pawel zak-pawel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it works very well, thanks!

@chavacava
Copy link
Collaborator

Hi @denisvmedia thanks for the PR, it LGTM.
Could you please add some test cases to the rule tests?

@denisvmedia
Copy link
Collaborator Author

@chavacava it's actually non-trivial to test it. We'll have to provide the means to pass fake imports in our test engine. Otherwise, any package we import won't be found and the tests will start failing. I played around with a custom (fake) importer, but I didn't have enough time to simulate the invalid package situation. I can try checking it later. Do you think we can merge this PR now without having the tests at the moment?

@chavacava
Copy link
Collaborator

IMO relying on actual type analysis is over-killing for such a simple rule.
I wonder if just comparing the string representation of parameters types is not enough.
A canonical string representation of parameters' types can be obtained by calling gofmt on each *Field.Type of FuncDecl.Type.Params.List.

@denisvmedia
Copy link
Collaborator Author

That's what my TODO comment actually says (maybe I wasn't clear enough in it ;)). But what I wanted is to have a quick fix to make sure that this rule at least doesn't have false positives (it seems to me to be better than having false negatives), and then invest some more time to have a full fix. But if you think it makes no sense to merge it as is, I can revise the PR. I'm just not sure when I will have time to play with it.

@denisvmedia denisvmedia merged commit 3249a5e into master Sep 23, 2024
4 checks passed
@denisvmedia denisvmedia deleted the ignore-invalid-types-in-enforce-repeated-arg-type-style branch September 23, 2024 11:48
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

Successfully merging this pull request may close these issues.

The enforce-repeated-arg-type-style rule finds some false positives.
3 participants