Skip to content

Commit b721f69

Browse files
authored
fix #622 (Rule 'var-naming' should allow Fuzz_xxx) (#623)
1 parent af953e6 commit b721f69

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

rule/var-naming.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ func (w *lintNames) Visit(n ast.Node) ast.Visitor {
145145
}
146146
}
147147
case *ast.FuncDecl:
148-
if w.file.IsTest() && (strings.HasPrefix(v.Name.Name, "Example") || strings.HasPrefix(v.Name.Name, "Test") || strings.HasPrefix(v.Name.Name, "Benchmark")) {
148+
funcName := v.Name.Name
149+
if w.file.IsTest() &&
150+
(strings.HasPrefix(funcName, "Example") ||
151+
strings.HasPrefix(funcName, "Test") ||
152+
strings.HasPrefix(funcName, "Benchmark") ||
153+
strings.HasPrefix(funcName, "Fuzz")) {
149154
return w
150155
}
151156

test/var-naming_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ func TestVarNaming(t *testing.T) {
1111
testRule(t, "var-naming", &rule.VarNamingRule{}, &lint.RuleConfig{
1212
Arguments: []interface{}{[]interface{}{"ID"}, []interface{}{"VM"}},
1313
})
14+
15+
testRule(t, "var-naming_test", &rule.VarNamingRule{}, &lint.RuleConfig{})
1416
}

testdata/var-naming_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test for name linting.
2+
3+
// Package pkg_with_underscores ...
4+
package varnaming_test
5+
6+
var var_name int // MATCH /don't use underscores in Go names; var var_name should be varName/
7+
8+
func Test_ATest() {}
9+
func Example_AnExample() {}
10+
func Benchmark_ABenchmark() {}
11+
12+
func Fuzz_AFuzz() {}

0 commit comments

Comments
 (0)