Skip to content

Commit c0d7d69

Browse files
committed
add nosnakecase lint
1 parent 86321a5 commit c0d7d69

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ require (
155155
github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 // indirect
156156
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 // indirect
157157
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
158+
github.com/sivchari/nosnakecase v1.0.0
158159
github.com/spf13/afero v1.8.2 // indirect
159160
github.com/spf13/cast v1.4.1 // indirect
160161
github.com/spf13/jwalterweatherman v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/nosnakecase.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/sivchari/nosnakecase"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewNoSnakeCase() *goanalysis.Linter {
11+
a := nosnakecase.Analyzer
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeSyntax)
19+
}

pkg/lint/lintersdb/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
541541
WithPresets(linter.PresetStyle).
542542
WithURL("https://github.com/firefart/nonamedreturns"),
543543

544+
linter.NewConfig(golinters.NewNoSnakeCase()).
545+
WithSince("v1.46.0").
546+
WithPresets(linter.PresetStyle).
547+
WithURL("https://github.com/sivchari/nosnakecase"),
548+
544549
linter.NewConfig(golinters.NewNoSprintfHostPort()).
545550
WithSince("v1.46.0").
546551
WithPresets(linter.PresetStyle).

test/testdata/nosnakecase.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// args: -Enosnakecase
2+
package testdata
3+
4+
func a_() { // ERROR "a_ is used under score. You should use mixedCap or MixedCap."
5+
}
6+
7+
func b(a_a int) { // ERROR "a_a is used under score. You should use mixedCap or MixedCap."
8+
}
9+
10+
func c() (c_c int) { // ERROR "c_c is used under score. You should use mixedCap or MixedCap."
11+
c_c = 1 // ERROR "c_c is used under score. You should use mixedCap or MixedCap."
12+
return c_c // ERROR "c_c is used under score. You should use mixedCap or MixedCap."
13+
}
14+
15+
func d() {
16+
var d_d int // ERROR "d_d is used under score. You should use mixedCap or MixedCap."
17+
_ = d_d // It's never detected, because `_` is meaningful in Go and `d_d` is already detected.
18+
}

0 commit comments

Comments
 (0)