File tree 4 files changed +22
-1
lines changed 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ Global variables are an input to functions that is not visible in the functions
13
13
https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html
14
14
https://twitter.com/davecheney/status/871939730761547776
15
15
16
+ ### Exceptions
17
+
18
+ There are very few exceptions to the global variable rule. This tool will ignore the following patterns:
19
+ * Variables with an ` Err ` prefix
20
+ * Variables named ` _ `
21
+ * Variables named ` version `
22
+
16
23
## Install
17
24
18
25
```
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
)
12
12
13
13
func isWhitelisted (i * ast.Ident ) bool {
14
- return i .Name == "_" || looksLikeError (i )
14
+ return i .Name == "_" || i . Name == "version" || looksLikeError (i )
15
15
}
16
16
17
17
// looksLikeError returns true if the AST identifier starts
Original file line number Diff line number Diff line change @@ -105,6 +105,13 @@ func TestCheckNoGlobals(t *testing.T) {
105
105
"testdata/8/code.go:30 declaredErr is a global variable" ,
106
106
},
107
107
},
108
+ {
109
+ path : "testdata/9" ,
110
+ wantMessages : []string {
111
+ "testdata/9/code.go:3 Version is a global variable" ,
112
+ "testdata/9/code.go:4 version22 is a global variable" ,
113
+ },
114
+ },
108
115
{
109
116
path : "." ,
110
117
wantMessages : nil ,
@@ -135,6 +142,8 @@ func TestCheckNoGlobals(t *testing.T) {
135
142
"testdata/8/code.go:20 myVarError is a global variable" ,
136
143
"testdata/8/code.go:21 customErr is a global variable" ,
137
144
"testdata/8/code.go:30 declaredErr is a global variable" ,
145
+ "testdata/9/code.go:3 Version is a global variable" ,
146
+ "testdata/9/code.go:4 version22 is a global variable" ,
138
147
},
139
148
},
140
149
}
Original file line number Diff line number Diff line change
1
+ package code
2
+
3
+ var Version string
4
+ var version22 string
5
+ var version string
You can’t perform that action at this time.
0 commit comments