abbrcase is a very simple Go linter that fails and reports when abbreviations in identifiers are not written in all caps
go install github.com/tuzgen/abbrcase@latest
The rules below apply to abbreviations defined under the abbrs flag.
- Any identifier that matches an abbreviation should be either all uppercase or all lowercase e.g. http or HTTP, not Http
When abbrs = http
package http // package name should not be reported as an error
import "fmt"
func findOrderByOrderID(orderId string) struct{} {
return struct{}{}
}
func createHttpServer() {
//...
}
func createHTTPServer() {
//...
}
func main() {
orderID := "asd"
orderId := "Ads"
createHTTPServer()
createHttpServer()
val := findOrderByOrderID(orderID)
fmt.Println(orderID, orderId, val)
}
abbrcase
on main [?] via v1.21.3
❮ ./abbrcase -abbrs=http ./...
/Users/oguztuzgen/Development/personal/abbrcase/examples/example.go:9:6: use all caps abbreviations: Http should be HTTP
/Users/oguztuzgen/Development/personal/abbrcase/examples/example.go:22:2: use all caps abbreviations: Http should be HTTP
Any form of static code analysis aims to improve code quality and avoid samey code review comments. This project also aims to tackle the same issues. It is just a niche problem I encountered in my personal experience.