add nosnakecase lint (#2828)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
3a0f646e31
commit
1d8a15a0cc
1
go.mod
1
go.mod
@ -155,6 +155,7 @@ require (
|
||||
github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 // indirect
|
||||
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 // indirect
|
||||
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
|
||||
github.com/sivchari/nosnakecase v1.5.0
|
||||
github.com/spf13/afero v1.8.2 // indirect
|
||||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
|
8
go.sum
generated
8
go.sum
generated
@ -617,6 +617,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sivchari/containedctx v1.0.2 h1:0hLQKpgC53OVF1VT7CeoFHk9YKstur1XOgfYIc1yrHI=
|
||||
github.com/sivchari/containedctx v1.0.2/go.mod h1:PwZOeqm4/DLoJOqMSIJs3aKqXRX4YO+uXww087KZ7Bw=
|
||||
github.com/sivchari/nosnakecase v1.5.0 h1:ZBvAu1H3uteN0KQ0IsLpIFOwYgPEhKLyv2ahrVkub6M=
|
||||
github.com/sivchari/nosnakecase v1.5.0/go.mod h1:CwDzrzPea40/GB6uynrNLiorAlgFRvRbFSgJx2Gs+QY=
|
||||
github.com/sivchari/tenv v1.6.0 h1:FyE4WysxLwYljKqWhTfOMjgKjBSnmzzg7lWOmpDiAcc=
|
||||
github.com/sivchari/tenv v1.6.0/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
@ -671,16 +673,10 @@ github.com/sylvia7788/contextcheck v1.0.4/go.mod h1:vuPKJMQ7MQ91ZTqfdyreNKwZjyUg
|
||||
github.com/tdakkota/asciicheck v0.1.1 h1:PKzG7JUTUmVspQTDqtkX9eSiLGossXTybutHwTXuO0A=
|
||||
github.com/tdakkota/asciicheck v0.1.1/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
|
||||
github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=
|
||||
github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=
|
||||
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
|
||||
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
|
||||
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
|
||||
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
|
||||
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
|
||||
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
|
||||
github.com/tetafro/godot v1.4.11 h1:BVoBIqAf/2QdbFmSwAWnaIqDivZdOV0ZRwEm6jivLKw=
|
||||
github.com/tetafro/godot v1.4.11 h1:BVoBIqAf/2QdbFmSwAWnaIqDivZdOV0ZRwEm6jivLKw=
|
||||
github.com/tetafro/godot v1.4.11/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
|
||||
github.com/tetafro/godot v1.4.11/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
|
||||
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=
|
||||
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
|
19
pkg/golinters/nosnakecase.go
Normal file
19
pkg/golinters/nosnakecase.go
Normal file
@ -0,0 +1,19 @@
|
||||
package golinters
|
||||
|
||||
import (
|
||||
"github.com/sivchari/nosnakecase"
|
||||
"golang.org/x/tools/go/analysis"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
||||
)
|
||||
|
||||
func NewNoSnakeCase() *goanalysis.Linter {
|
||||
a := nosnakecase.Analyzer
|
||||
|
||||
return goanalysis.NewLinter(
|
||||
a.Name,
|
||||
a.Doc,
|
||||
[]*analysis.Analyzer{a},
|
||||
nil,
|
||||
).WithLoadMode(goanalysis.LoadModeSyntax)
|
||||
}
|
@ -631,6 +631,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
||||
WithPresets(linter.PresetStyle).
|
||||
WithURL("https://github.com/firefart/nonamedreturns"),
|
||||
|
||||
linter.NewConfig(golinters.NewNoSnakeCase()).
|
||||
WithSince("v1.47.0").
|
||||
WithPresets(linter.PresetStyle).
|
||||
WithURL("https://github.com/sivchari/nosnakecase"),
|
||||
|
||||
linter.NewConfig(golinters.NewNoSprintfHostPort()).
|
||||
WithSince("v1.46.0").
|
||||
WithPresets(linter.PresetStyle).
|
||||
|
@ -95,7 +95,7 @@ func TestTestsAreLintedByDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCgoOk(t *testing.T) {
|
||||
testshared.NewLintRunner(t).Run("--no-config", "--enable-all", getTestDataDir("cgo")).ExpectNoIssues()
|
||||
testshared.NewLintRunner(t).Run("--no-config", "--enable-all", "-D", "nosnakecase", getTestDataDir("cgo")).ExpectNoIssues()
|
||||
}
|
||||
|
||||
func TestCgoWithIssues(t *testing.T) {
|
||||
|
149
test/testdata/nosnakecase.go
vendored
Normal file
149
test/testdata/nosnakecase.go
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
//args: -Enosnakecase
|
||||
package testdata
|
||||
|
||||
import (
|
||||
_ "fmt"
|
||||
f_m_t "fmt" // ERROR "f_m_t contains underscore. You should use mixedCap or MixedCap."
|
||||
)
|
||||
|
||||
// global variable name with underscore.
|
||||
var v_v = 0 // ERROR "v_v contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// global constant name with underscore.
|
||||
const c_c = 0 // ERROR "c_c contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// struct name with underscore.
|
||||
type S_a struct { // ERROR "S_a contains underscore. You should use mixedCap or MixedCap."
|
||||
fi int
|
||||
}
|
||||
|
||||
// non-exported struct field name with underscore.
|
||||
type Sa struct {
|
||||
fi_a int // // ERROR "fi_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// function as struct field, with parameter name with underscore.
|
||||
type Sb struct {
|
||||
fib func(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// exported struct field with underscore.
|
||||
type Sc struct {
|
||||
Fi_A int // ERROR "Fi_A contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// function as struct field, with return name with underscore.
|
||||
type Sd struct {
|
||||
fib func(p int) (r_a int) // ERROR "r_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// interface name with underscore.
|
||||
type I_a interface { // ERROR "I_a contains underscore. You should use mixedCap or MixedCap."
|
||||
fn(p int)
|
||||
}
|
||||
|
||||
// interface with parameter name with underscore.
|
||||
type Ia interface {
|
||||
fn(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// interface with parameter name with underscore.
|
||||
type Ib interface {
|
||||
Fn(p_a int) // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// function as struct field, with return name with underscore.
|
||||
type Ic interface {
|
||||
Fn_a() // ERROR "Fn_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// interface with return name with underscore.
|
||||
type Id interface {
|
||||
Fn() (r_a int) // ERROR "r_a contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// function name with underscore.
|
||||
func f_a() {} // ERROR "f_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// function's parameter name with underscore.
|
||||
func fb(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// named return with underscore.
|
||||
func fc() (r_b int) { // ERROR "r_b contains underscore. You should use mixedCap or MixedCap."
|
||||
return 0
|
||||
}
|
||||
|
||||
// local variable (short declaration) with underscore.
|
||||
func fd(p int) int {
|
||||
v_b := p * 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// local constant with underscore.
|
||||
func fe(p int) int {
|
||||
const v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// local variable with underscore.
|
||||
func ff(p int) int {
|
||||
var v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// inner function, parameter name with underscore.
|
||||
func fg() {
|
||||
fgl := func(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
fgl(1)
|
||||
}
|
||||
|
||||
type Foo struct{}
|
||||
|
||||
// method name with underscore.
|
||||
func (f Foo) f_a() {} // ERROR "f_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// method's parameter name with underscore.
|
||||
func (f Foo) fb(p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// named return with underscore.
|
||||
func (f Foo) fc() (r_b int) { return 0 } // ERROR "r_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
// local variable (short declaration) with underscore.
|
||||
func (f Foo) fd(p int) int {
|
||||
v_b := p * 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// local constant with underscore.
|
||||
func (f Foo) fe(p int) int {
|
||||
const v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
// local variable with underscore.
|
||||
func (f Foo) ff(p int) int {
|
||||
var v_b = 2 // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
return v_b * p // ERROR "v_b contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
||||
|
||||
func fna(a, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
func fna1(a string, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
func fnb(a, b, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
func fnb1(a, b string, p_a int) {} // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
|
||||
func fnd(
|
||||
p_a int, // ERROR "p_a contains underscore. You should use mixedCap or MixedCap."
|
||||
p_b int, // ERROR "p_b contains underscore. You should use mixedCap or MixedCap."
|
||||
p_c int, // ERROR "p_c contains underscore. You should use mixedCap or MixedCap."
|
||||
) {
|
||||
f_m_t.Println("") // ERROR "f_m_t contains underscore. You should use mixedCap or MixedCap."
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user