-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add pkgname linter #5899
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
Add pkgname linter #5899
Conversation
|
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements.
Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
I feel like it should be a part of |
The cited references are distorted from their meaning: package names are not package aliases. |
It is for package name. Primarily the linter checks the package name to be Go idiomatic. Also put the same rule if in config From the official Go resources, this Go idiomatic is only for package naming not for package alias. That is why the importas seems has different goal, focus on alias consistency through pattern enforcement:
|
I recommend avoiding reopening a PR before having feedback. |
May I know whether this is final or need more justification to move forward? |
I am working on something else, I will provide feedback later |
Related: https://revive.run/r#var-naming |
Interesting. @alexandear I haven't use it before. I read the doc seeing that this is rule for var naming and optionally for package naming? How it behave? |
It has the same rules as your readme around package names and you can combine it with › head -n7 **/*.go
==> badName/badName.go <==
package badName
==> bad_import/bad_import.go <==
package badimport
import (
badImport "fmt"
bad_import "fmt"
okimport "fmt"
)
==> bad_name/bad_name.go <==
package bad_name › cat .golangci.yaml
---
version: "2"
linters:
default: none
enable:
- revive
settings:
revive:
rules:
- name: var-naming
- name: import-alias-naming › golangci-lint run
badName/badName.go:1:9: var-naming: don't use MixedCaps in package name; badName should be badname (revive)
package badName
^
bad_import/bad_import.go:4:2: import-alias-naming: import name (badImport) must match the regular expression: ^[a-z][a-z0-9]{0,}$ (revive)
badImport "fmt"
^
bad_import/bad_import.go:5:2: import-alias-naming: import name (bad_import) must match the regular expression: ^[a-z][a-z0-9]{0,}$ (revive)
bad_import "fmt"
^
bad_name/bad_name.go:1:9: var-naming: don't use an underscore in package name (revive)
package bad_name
^
4 issues:
* revive: 4 |
Add pkgname linter.
This linter encourage us to follow Go idiomatic package name.
The Go Blog: Package names
The Go Blog: Package names
Effective Go - Package names