pkgnaming
About 266 wordsLess than 1 minute
2025-01-16
Enforces package naming conventions to avoid stutter.
Category
Architecture
What It Checks
This analyzer detects package names that cause "stutter" when used with their exported symbols.
Why It Matters
Package stutter is redundant and verbose:
user.UserService // "user" appears twice
http.HTTPClient // "http" appears twice
config.ConfigLoader // "config" appears twiceExamples
Bad: Stutter
// In package user
package user
type UserService struct{} // user.UserService stutters
type UserRepository struct{} // user.UserRepository stutters
func NewUserService() *UserService {} // user.NewUserService stuttersGood: No Stutter
// In package user
package user
type Service struct{} // user.Service is clear
type Repository struct{} // user.Repository is clear
func NewService() *Service {} // user.NewService is clearBad: Package Name Repetition
// In package httputil
package httputil
type HTTPClient struct{} // httputil.HTTPClient stutters on "HTTP"Good: Clear Names
// In package httputil
package httputil
type Client struct{} // httputil.Client is clearPackage Naming Guidelines
Short, lowercase, no underscores
Good: user, http, config Bad: user_service, httpClient, ConfigException: External test packages (
*_test) are allowed as this is Go's standard convention for black-box testing:Allowed: user_test (external test package for user)Singular, not plural
Good: user (for package about users) Bad: usersDescriptive but concise
Good: auth, storage, cache Bad: authentication, datastorage, memorycache
Configuration
# .golint-sl.yaml
analyzers:
pkgnaming: true # enabled by defaultWhen to Disable
- Generated code with fixed names
- Compatibility with external conventions
analyzers:
pkgnaming: falseRelated Analyzers
- exporteddoc - Export documentation
