Skip to content

Commit

Permalink
Using simplest for of integration possible
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankgb committed Nov 15, 2020
1 parent fd12de4 commit 621a5f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 1 addition & 3 deletions go.mod
Expand Up @@ -73,6 +73,4 @@ require (
mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7
)

replace (
github.com/jgautheron/goconst => github.com/iwankgb/goconst v0.0.0-20201113193136-4c8fa7523232
)
replace github.com/jgautheron/goconst => github.com/iwankgb/goconst v0.0.0-20201115195935-66b9063f334d
12 changes: 12 additions & 0 deletions go.sum

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

10 changes: 5 additions & 5 deletions pkg/golinters/goconst.go
Expand Up @@ -53,8 +53,11 @@ func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.
ParseNumbers: lintCtx.Settings().Goconst.ParseNumbers,
NumberMin: lintCtx.Settings().Goconst.NumberMin,
NumberMax: lintCtx.Settings().Goconst.NumberMax,
ExcludeTypes: map[goconstAPI.Type]bool{},
}
if lintCtx.Settings().Goconst.IgnoreCalls {
cfg.ExcludeTypes[goconstAPI.Call] = true
}

goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
if err != nil {
return nil, err
Expand All @@ -66,10 +69,7 @@ func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.

res := make([]goanalysis.Issue, 0, len(goconstIssues))
for _, i := range goconstIssues {
if lintCtx.Settings().Goconst.IgnoreCalls && i.Typ == goconstAPI.Call {
continue
}
textBegin := fmt.Sprintf("string %s has %d occurrences as %s statement", formatCode(i.Str, lintCtx.Cfg), i.OccurrencesCount, i.Typ)
textBegin := fmt.Sprintf("string %s has %d occurrences", formatCode(i.Str, lintCtx.Cfg), i.OccurrencesCount)
var textEnd string
if i.MatchingConst == "" {
textEnd = ", make it a constant"
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/goconst.go
Expand Up @@ -4,7 +4,7 @@ package testdata
import "fmt"

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

func GoconstC() {
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences as assignment statement, but such constant `AlreadyHasConst` already exists"
a := "alreadyhasconst" // ERROR "string `alreadyhasconst` has 3 occurrences, but such constant `AlreadyHasConst` already exists"
fmt.Print(a)
b := "alreadyhasconst"
fmt.Print(b)
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/goconst_calls_enabled.go
Expand Up @@ -7,11 +7,11 @@ import "fmt"
const FooBar = "foobar"

func Baz() {
a := "foobar" // ERROR "string `foobar` has 3 occurrences as assignment statement, but such constant `FooBar` already exists"
a := "foobar" // ERROR "string `foobar` has 4 occurrences, but such constant `FooBar` already exists"
fmt.Print(a)
b := "foobar"
fmt.Print(b)
c := "foobar"
fmt.Print(c)
fmt.Print("foobar") // ERROR "string `foobar` has 1 occurrences as call statement, but such constant `FooBar` already exists"
fmt.Print("foobar")
}

0 comments on commit 621a5f2

Please sign in to comment.