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

package-comments complains for no reason #922

Closed
marcelloh opened this issue Oct 26, 2023 · 4 comments · Fixed by #989
Closed

package-comments complains for no reason #922

marcelloh opened this issue Oct 26, 2023 · 4 comments · Fixed by #989
Assignees

Comments

@marcelloh
Copy link

Describe the bug
I have a package comment (in a doc.go), but when I have a comment in another file inside the same package, it complains that it isn't a good one.

To Reproduce
make one valid package comment in a package
My doc.go example

/*
Package migrations holds database migrations and seeders.
*/
package migrations

Now add in another file a comment not being a package comment

I use revive version 1.3.4

revive -formatter friendly -exclude ./vendor/... ./...
no toml

Expected behavior
N0 complains, because there is a valid package comment in the package

Logs

Desktop (please complete the following information):

  • OS: Mac Os 14 (Sonoma)
  • go version go1.21.3 darwin/arm64

Additional context

@chavacava
Copy link
Collaborator

Hi @marcelloh, thanks for reporting this issue.
Could you please provide:

  1. An example of add in another file a comment not being a package comment
  2. The actual failure generated by revive
    ?

@marcelloh
Copy link
Author

marcelloh commented Oct 26, 2023

Example (what you can put on top of the other file in the same package)

//nolint:dupl,revive // looks the same but isn't

package migrations

and message is:

─── revive version 1.3.4
  ⚠  https://revive.run/r#package-comments  package comment should be of the form "Package migrations ..."  
  services/migrations/languageMigration.go:1:1

@chavacava
Copy link
Collaborator

Thanks.
IMO the behavior of the rule is OK. The comment attached to the package declaration does not respect the conventions enforced by the rule.
Must the rule warn in this case even if there is another file in the package where the convention is respected? I think it must.
What do you think?

@marcelloh
Copy link
Author

marcelloh commented Oct 29, 2023

There should be a valid package comment present in the package. In my example, there is
There is only one valid package comment in all the files in the package. Not every file needs to have the same comment.
This means that revive should not complain if it find extra comments that don't fit the valid comment.

The fact i'm running golangci-lint (with inside revive) and after that some separate linters, also with revive), gives this effect.
Perhaps if I change the first line :

//revive:disable
//nolint:dupl,revive // looks the same but isn't
//revive:enable
package migrations

this probably works but looks really ugly

@chavacava chavacava self-assigned this May 10, 2024
@chavacava chavacava mentioned this issue May 11, 2024
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 a pull request may close this issue.

2 participants