Skip to content

Commit

Permalink
Bump github.com/jgautheron/goconst from 0.5.6 to 0.5.7(#2044)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetorpedodog committed Jun 9, 2021
1 parent 2862ca6 commit 52b5514
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5
github.com/gostaticanalysis/nilerr v0.1.1
github.com/hashicorp/go-multierror v1.1.1
github.com/jgautheron/goconst v1.4.0
github.com/jgautheron/goconst v1.5.1
github.com/jingyugao/rowserrcheck v1.1.0
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d
Expand Down
6 changes: 2 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ type GocognitSettings struct {
}

type GoConstSettings struct {
IgnoreTests bool `mapstructure:"ignore-tests"`
MatchWithConstants bool `mapstructure:"match-constant"`
MinStringLen int `mapstructure:"min-len"`
MinOccurrencesCount int `mapstructure:"min-occurrences"`
Expand Down
1 change: 1 addition & 0 deletions pkg/golinters/goconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewGoconst() *goanalysis.Linter {

func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
cfg := goconstAPI.Config{
IgnoreTests: lintCtx.Settings().Goconst.IgnoreTests,
MatchWithConstants: lintCtx.Settings().Goconst.MatchWithConstants,
MinStringLength: lintCtx.Settings().Goconst.MinStringLen,
MinOccurrences: lintCtx.Settings().Goconst.MinOccurrencesCount,
Expand Down
36 changes: 36 additions & 0 deletions test/testdata/goconst_dont_ignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//args: -Egoconst
//config: linters-settings.goconst.ignore-tests=false
package testdata

import (
"fmt"
"testing"
)

func TestGoConstA(t *testing.T) {
a := "needconst" // ERROR "string `needconst` has 5 occurrences, make it a constant"
fmt.Print(a)
b := "needconst"
fmt.Print(b)
c := "needconst"
fmt.Print(c)
}

func TestGoConstB(t *testing.T) {
a := "needconst"
fmt.Print(a)
b := "needconst"
fmt.Print(b)
}

const AlreadyHasConst = "alreadyhasconst"

func TestGoConstC(t *testing.T) {
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists"
fmt.Print(a)
b := "alreadyhasconst"
fmt.Print(b)
c := "alreadyhasconst"
fmt.Print(c)
fmt.Print("alreadyhasconst")
}
36 changes: 36 additions & 0 deletions test/testdata/goconst_ignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//args: -Egoconst
//config: linters-settings.goconst.ignore-tests=true
package testdata

import (
"fmt"
"testing"
)

func TestGoConstA(t *testing.T) {
a := "needconst"
fmt.Print(a)
b := "needconst"
fmt.Print(b)
c := "needconst"
fmt.Print(c)
}

func TestGoConstB(t *testing.T) {
a := "needconst"
fmt.Print(a)
b := "needconst"
fmt.Print(b)
}

const AlreadyHasConst = "alreadyhasconst"

func TestGoConstC(t *testing.T) {
a := "alreadyhasconst"
fmt.Print(a)
b := "alreadyhasconst"
fmt.Print(b)
c := "alreadyhasconst"
fmt.Print(c)
fmt.Print("alreadyhasconst")
}

0 comments on commit 52b5514

Please sign in to comment.