gogolint

Why is go-lint is giving inconsistent suggestions about initialisms?


go-lint is suggesting the following:

method CreateStaticCssPath should be CreateStaticCSSPath

Is the linter correct and if so why?

It allowed the previous method:

CreateStaticJsPath

Solution

  • Go naming convention dictates that initialisms should be written in all-caps (actually: in consistent case, depending on whether the first character should be capitalized or not). This is what the linter is complaining about.

    Words in names that are initialisms or acronyms (e.g. "URL" or "NATO") have a consistent case. For example, "URL" should appear as "URL" or "url" (as in "urlPony", or "URLPony"), never as "Url". As an example: ServeHTTP not ServeHttp. For identifiers with multiple initialized "words", use for example "xmlHTTPRequest" or "XMLHTTPRequest".

    This rule also applies to "ID" when it is short for "identifier" (which is pretty much all cases when it's not the "id" as in "ego", "superego"), so write "appID" instead of "appId".

    Therefore, assuming that CSS and JS are initialisms, CreateStaticCSSPath and CreateStaticJSPath would be the "Go way" to write each of these symbol names.

    Although the linter's catching of these failures is naturally limited. It's impossible to be 100% accurate here, since context (and human intuition) is necessary.

    CreateJs might mean "create JavaScript" or it might mean "create more than one J" (whatever a "J" is in context).

    I expect the linter has a hard-coded list of common initialisms (CSS, URL, HTML, ID, etc), that are expected to have a very low false positive rate, and looks just for those. Anything else quickly strays into the realm of madness when trying to parse terse symbol names to human-understandable text.