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

nested-structs false positives with "struct{}" #824

Closed
sbunce opened this issue May 14, 2023 · 5 comments · Fixed by #829
Closed

nested-structs false positives with "struct{}" #824

sbunce opened this issue May 14, 2023 · 5 comments · Fixed by #829
Assignees
Labels

Comments

@sbunce
Copy link

sbunce commented May 14, 2023

I found some instances of "struct{}" causing the nested-structs check to fail. Based on other issues it looks like the intention is to not include struct{} in this check.

type test struct {
  foo []chan struct{}
  bar map[string]struct{}
}

If this is working as intended feel free to resolve.

p.s. Revive works great! Found multiple bugs in my code.

@mgechev
Copy link
Owner

mgechev commented May 15, 2023

Thank you!

Can't reproduce it in #826. Would you share another example which gives you the false positive?

@sbunce
Copy link
Author

sbunce commented May 16, 2023

I created a draft pull request which shows the issue. #828

I think it's an issue in the "nested-structs" rule.

Running "make test" shows the following.

    utils.go:120: Unexpected problem at nested-structs.go:50: no nested structs are allowed
    utils.go:120: Unexpected problem at nested-structs.go:51: no nested structs are allowed
--- FAIL: TestNestedStructs (0.00s)

@chavacava chavacava self-assigned this May 16, 2023
@chavacava
Copy link
Collaborator

chavacava commented May 16, 2023

Hi @sbunce, thanks for the PR with the example. I'll check for a solution.

@chavacava chavacava added bug and removed question labels May 16, 2023
chavacava added a commit that referenced this issue May 16, 2023
@chavacava chavacava mentioned this issue May 16, 2023
chavacava added a commit that referenced this issue May 16, 2023
@chavacava
Copy link
Collaborator

@sbunce please let me know if the fix works for your cases. If that is the case, you can close the PR #828
Thanks again!

@sbunce
Copy link
Author

sbunce commented May 17, 2023

Fix works. Thank you!

I found one more tiny one with generics.

type test struct {
	baz generic[struct{}]   // Must not match
}

type generic [T any] struct {}

The error points at the "baz" field.

=== RUN   TestNestedStructs
    utils.go:119: Unexpected problem at nested-structs.go:64: no nested structs are allowed
--- FAIL: TestNestedStructs (0.00s)

I added the example to my draft PR. https://github.com/mgechev/revive/pull/828/files

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

Successfully merging a pull request may close this issue.

3 participants