I made get commonInitialisms library(Using go/ast)


Hello. I made get commonInitialisms library for Go.

commonInitialism is words that should be written in uppercase on Go. (e.g. ID, JSON, URL, SQL)

Why need it

commonInitialism is defined "golang.org/x/lint" package.

// commonInitialisms is a set of common initialisms.
// Only add entries that are highly unlikely to be non-initialisms.
// For instance, "ID" is fine (Freudian code is rare), but "AND" is not.
var commonInitialisms = map[string]bool{
    "ACL":   true,
    "API":   true,
    "ASCII": true,
    "XSS":   true,


I often think want to use it, when develop using ast.
But this variable is unexported value. Also It will not change in the future.

Often copied and used it. github.com/search?q=commonInitialisms.

Everyone will be doing it unavoidably. If new word is added to commonInitialisms on lint pacakge, can't notice.

It is automatically updated in my library.(unless not change file name or variable name)

How it was made

I used golang.org/x/lint, go/ast, go/parser, go/token, and golang.org/x/tools/go/packages libraries.

  1. Blank import golang.org/x/lint
  2. Search out golang.org/x/lint/lint.go, And get as Go file.(using packages)
  3. Parsed it.(using go/token and go/parser)
  4. Search commonInitialism variable.(using go/ast)


Please create Issue and Pull Request.

<< Contentful+Netlify+Nextにブログ移行しました。
ISUCON8の予選で敗戦した話と感想戦で1位の点数を超えるまで頑張った話 >>
Web engineer.