Skip to content

Commit 52b5514

Browse files
Bump github.com/jgautheron/goconst from 0.5.6 to 0.5.7(#2044)
1 parent 2862ca6 commit 52b5514

File tree

6 files changed

+77
-5
lines changed

6 files changed

+77
-5
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5
3535
github.com/gostaticanalysis/nilerr v0.1.1
3636
github.com/hashicorp/go-multierror v1.1.1
37-
github.com/jgautheron/goconst v1.4.0
37+
github.com/jgautheron/goconst v1.5.1
3838
github.com/jingyugao/rowserrcheck v1.1.0
3939
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
4040
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d

go.sum

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ type GocognitSettings struct {
200200
}
201201

202202
type GoConstSettings struct {
203+
IgnoreTests bool `mapstructure:"ignore-tests"`
203204
MatchWithConstants bool `mapstructure:"match-constant"`
204205
MinStringLen int `mapstructure:"min-len"`
205206
MinOccurrencesCount int `mapstructure:"min-occurrences"`

pkg/golinters/goconst.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func NewGoconst() *goanalysis.Linter {
4747

4848
func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
4949
cfg := goconstAPI.Config{
50+
IgnoreTests: lintCtx.Settings().Goconst.IgnoreTests,
5051
MatchWithConstants: lintCtx.Settings().Goconst.MatchWithConstants,
5152
MinStringLength: lintCtx.Settings().Goconst.MinStringLen,
5253
MinOccurrences: lintCtx.Settings().Goconst.MinOccurrencesCount,
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//args: -Egoconst
2+
//config: linters-settings.goconst.ignore-tests=false
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
)
9+
10+
func TestGoConstA(t *testing.T) {
11+
a := "needconst" // ERROR "string `needconst` has 5 occurrences, make it a constant"
12+
fmt.Print(a)
13+
b := "needconst"
14+
fmt.Print(b)
15+
c := "needconst"
16+
fmt.Print(c)
17+
}
18+
19+
func TestGoConstB(t *testing.T) {
20+
a := "needconst"
21+
fmt.Print(a)
22+
b := "needconst"
23+
fmt.Print(b)
24+
}
25+
26+
const AlreadyHasConst = "alreadyhasconst"
27+
28+
func TestGoConstC(t *testing.T) {
29+
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists"
30+
fmt.Print(a)
31+
b := "alreadyhasconst"
32+
fmt.Print(b)
33+
c := "alreadyhasconst"
34+
fmt.Print(c)
35+
fmt.Print("alreadyhasconst")
36+
}

test/testdata/goconst_ignore_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//args: -Egoconst
2+
//config: linters-settings.goconst.ignore-tests=true
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
)
9+
10+
func TestGoConstA(t *testing.T) {
11+
a := "needconst"
12+
fmt.Print(a)
13+
b := "needconst"
14+
fmt.Print(b)
15+
c := "needconst"
16+
fmt.Print(c)
17+
}
18+
19+
func TestGoConstB(t *testing.T) {
20+
a := "needconst"
21+
fmt.Print(a)
22+
b := "needconst"
23+
fmt.Print(b)
24+
}
25+
26+
const AlreadyHasConst = "alreadyhasconst"
27+
28+
func TestGoConstC(t *testing.T) {
29+
a := "alreadyhasconst"
30+
fmt.Print(a)
31+
b := "alreadyhasconst"
32+
fmt.Print(b)
33+
c := "alreadyhasconst"
34+
fmt.Print(c)
35+
fmt.Print("alreadyhasconst")
36+
}

0 commit comments

Comments
 (0)