Commit ab39c45
committed
unexportedglobal: Linter to require '_' prefix on globals
This adds a unexportedglobal to golangci-lint.
[unexportedglobal][1] is a linter that requires that
unexported global variables and constants are prefixed with '_'.
[1]: https://github.com/abhinav/unexportedglobal
```go
package foo
// Bad
var pool = sync.Pool{ /* ... */ }
// Good
var _pool = sync.Pool{ /* ... */ }
```
The idea is to eliminate the risk of conflict between
names of local variables and names of global variables.
The linter is inspired by the [Prefix Unexported Globals with `_`][2]
guidance in [Uber's Go Style Guide][3].
[2]: https://github.com/uber-go/guide/blob/master/style.md#prefix-unexported-globals-with-_
[3]: https://github.com/uber-go/guide/blob/master/style.md
The linter is not enabled by default.
I have also not added it to the 'style' preset
because not everyone may agree with this change.1 parent 0d191c9 commit ab39c45
File tree
6 files changed
+53
-9
lines changed- pkg
- golinters
- lint/lintersdb
- test/testdata
6 files changed
+53
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2175 | 2175 | | |
2176 | 2176 | | |
2177 | 2177 | | |
| 2178 | + | |
2178 | 2179 | | |
2179 | 2180 | | |
2180 | 2181 | | |
| |||
2289 | 2290 | | |
2290 | 2291 | | |
2291 | 2292 | | |
| 2293 | + | |
2292 | 2294 | | |
2293 | 2295 | | |
2294 | 2296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
188 | | - | |
| 189 | + | |
189 | 190 | | |
190 | | - | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
820 | 827 | | |
821 | 828 | | |
822 | 829 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments