var-naming
What it does
Section titled “What it does”Reports a name that is not spelled in Go style: it has an underscore, it is a constant in ALL_CAPS, or it writes a common initialism (Id, Http, Url) in mixed case. Checked are functions and methods with their parameters and results, the methods of interfaces (their parameters and results, not their names), constants, variables, types, the names of := and the fields of structs. Receivers, function literals and function types are not checked. The options initialisms and ignore_pattern change the words and names.
Why it matters
Section titled “Why it matters”Go code is read with the conventions of the standard library, where userID and ServeHTTP are written the same everywhere. A name that follows another style stands out and makes grep and completion less predictable.
To fix, rename to mixed caps with initialisms in capitals: userID, not user_id or userId.
Example
Section titled “Example”...
const MAX_VALUE = 1const ok_, maxA = 1, 2
var userId, other_name int
type Cpu struct { Id, name_x int _, fine int...
func get_value(url_s, userID string, rest_ ...int) (out_x int) { x_y := 1 f := func(lit_a int) {}...
func (r_x *T) Method(a_b int) {}
type I interface { Do_it(arg_a int) (res_a int)}
var LastInsertId, startHttpServer, v1_2 intConfiguration
Section titled “Configuration”go: lint: rules: var-naming: level: warn # off (default), warn, error options: names: "words" initialisms: ["ACL","API","ASCII","CPU","CSS","DNS","EOF","GUID","HTML","HTTP","HTTPS","ID","IDS","IP","JSON","LHS","QPS","RAM","RHS","RPC","SLA","SMTP","SQL","SSH","TCP","TLS","TTL","UDP","UI","UID","UUID","URI","URL","UTF8","VM","XML","XMPP","XSRF","XSS"] ignore_pattern: "^(LastInsertId|kWh)$"| Option | Type | Default | Description |
|---|---|---|---|
names |
string | "words" |
The convention of the names: words or off.Values: words, off |
initialisms |
list | ["ACL","API","ASCII","CPU","CSS","DNS","EOF","GUID","HTML","HTTP","HTTPS","ID","IDS","IP","JSON","LHS","QPS","RAM","RHS","RPC","SLA","SMTP","SQL","SSH","TCP","TLS","TTL","UDP","UI","UID","UUID","URI","URL","UTF8","VM","XML","XMPP","XSRF","XSS"] |
The words (in capitals) that are written in capitals inside a name. |
ignore_pattern |
string | `“^(LastInsertId | kWh)$“` |
Enabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line var-naming in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | var-naming |
full |