Skip to content

Commit 4706e66

Browse files
committed
Using simplest for of integration possible
1 parent fd12de4 commit 4706e66

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ require (
7474
)
7575

7676
replace (
77-
github.com/jgautheron/goconst => github.com/iwankgb/goconst v0.0.0-20201113193136-4c8fa7523232
77+
github.com/jgautheron/goconst => github.com/iwankgb/goconst v0.0.0-20201115195935-66b9063f334d
7878
)

go.sum

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

pkg/golinters/goconst.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.
5353
ParseNumbers: lintCtx.Settings().Goconst.ParseNumbers,
5454
NumberMin: lintCtx.Settings().Goconst.NumberMin,
5555
NumberMax: lintCtx.Settings().Goconst.NumberMax,
56+
ExcludeTypes: map[goconstAPI.Type]bool{},
57+
}
58+
if lintCtx.Settings().Goconst.IgnoreCalls {
59+
cfg.ExcludeTypes[goconstAPI.Call] = true
5660
}
57-
5861
goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
5962
if err != nil {
6063
return nil, err
@@ -66,10 +69,7 @@ func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.
6669

6770
res := make([]goanalysis.Issue, 0, len(goconstIssues))
6871
for _, i := range goconstIssues {
69-
if lintCtx.Settings().Goconst.IgnoreCalls && i.Typ == goconstAPI.Call {
70-
continue
71-
}
72-
textBegin := fmt.Sprintf("string %s has %d occurrences as %s statement", formatCode(i.Str, lintCtx.Cfg), i.OccurrencesCount, i.Typ)
72+
textBegin := fmt.Sprintf("string %s has %d occurrences", formatCode(i.Str, lintCtx.Cfg), i.OccurrencesCount)
7373
var textEnd string
7474
if i.MatchingConst == "" {
7575
textEnd = ", make it a constant"

test/testdata/goconst.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package testdata
44
import "fmt"
55

66
func GoconstA() {
7-
a := "needconst" // ERROR "string `needconst` has 5 occurrences as assignment statement, make it a constant"
7+
a := "needconst" // ERROR "string `needconst` has 5 occurrences, make it a constant"
88
fmt.Print(a)
99
b := "needconst"
1010
fmt.Print(b)
@@ -22,7 +22,7 @@ func GoconstB() {
2222
const AlreadyHasConst = "alreadyhasconst"
2323

2424
func GoconstC() {
25-
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences as assignment statement, but such constant `AlreadyHasConst` already exists"
25+
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists"
2626
fmt.Print(a)
2727
b := "alreadyhasconst"
2828
fmt.Print(b)

test/testdata/goconst_calls_enabled.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import "fmt"
77
const FooBar = "foobar"
88

99
func Baz() {
10-
a := "foobar" // ERROR "string `foobar` has 3 occurrences as assignment statement, but such constant `FooBar` already exists"
10+
a := "foobar" // ERROR "string `foobar` has 4 occurrences, but such constant `FooBar` already exists"
1111
fmt.Print(a)
1212
b := "foobar"
1313
fmt.Print(b)
1414
c := "foobar"
1515
fmt.Print(c)
16-
fmt.Print("foobar") // ERROR "string `foobar` has 1 occurrences as call statement, but such constant `FooBar` already exists"
16+
fmt.Print("foobar")
1717
}

0 commit comments

Comments
 (0)