diff --git a/.golangci.reference.yml b/.golangci.reference.yml index be547461a2b0..fef51fd52dcf 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1435,9 +1435,12 @@ linters-settings: # Optimizes `fmt.Errorf`. # Default: true errorf: false - # Optimizes `fmt.Sprintf` with only one argument + # Optimizes `fmt.Sprintf` with only one argument. # Default: true sprintf1: false + # Optimizes into strings concatenation. + # Default: true + strconcat: false prealloc: # IMPORTANT: we don't recommend using this linter before doing performance profiling. diff --git a/go.mod b/go.mod index 6406566b1891..648426ff89a7 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/breml/errchkjson v0.3.6 github.com/butuzov/ireturn v0.3.0 github.com/butuzov/mirror v1.1.0 - github.com/catenacyber/perfsprint v0.6.0 + github.com/catenacyber/perfsprint v0.7.0 github.com/charithe/durationcheck v0.0.10 github.com/curioswitch/go-reassign v0.2.0 github.com/daixiang0/gci v0.12.1 diff --git a/go.sum b/go.sum index 7f2c82f945c6..b6caea8249d7 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/butuzov/ireturn v0.3.0 h1:hTjMqWw3y5JC3kpnC5vXmFJAWI/m31jaCYQqzkS6PL0 github.com/butuzov/ireturn v0.3.0/go.mod h1:A09nIiwiqzN/IoVo9ogpa0Hzi9fex1kd9PSD6edP5ZA= github.com/butuzov/mirror v1.1.0 h1:ZqX54gBVMXu78QLoiqdwpl2mgmoOJTk7s4p4o+0avZI= github.com/butuzov/mirror v1.1.0/go.mod h1:8Q0BdQU6rC6WILDiBM60DBfvV78OLJmMmixe7GF45AE= -github.com/catenacyber/perfsprint v0.6.0 h1:VSv95RRkk5+BxrU/YTPcnxuMEWar1iMK5Vyh3fWcBfs= -github.com/catenacyber/perfsprint v0.6.0/go.mod h1:/wclWYompEyjUD2FuIIDVKNkqz7IgBIWXIH3V0Zol50= +github.com/catenacyber/perfsprint v0.7.0 h1:rKQKns5tJLHtB52z/1KZ4V2NlYnyJa7MAthhoM3I3Zk= +github.com/catenacyber/perfsprint v0.7.0/go.mod h1:/wclWYompEyjUD2FuIIDVKNkqz7IgBIWXIH3V0Zol50= github.com/ccojocar/zxcvbn-go v1.0.2 h1:na/czXU8RrhXO4EZme6eQJLR4PzcGsahsBOAwU6I3Vg= github.com/ccojocar/zxcvbn-go v1.0.2/go.mod h1:g1qkXtUSvHP8lhHp5GrSmTz6uWALGRMQdw6Qnz/hi60= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index a3206f597824..b950cb9b7b4e 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -112,6 +112,7 @@ var defaultLintersSettings = LintersSettings{ ErrError: false, ErrorF: true, SprintF1: true, + StrConcat: true, }, Prealloc: PreallocSettings{ Simple: true, @@ -711,6 +712,7 @@ type PerfSprintSettings struct { ErrError bool `mapstructure:"err-error"` ErrorF bool `mapstructure:"errorf"` SprintF1 bool `mapstructure:"sprintf1"` + StrConcat bool `mapstructure:"strconcat"` } type PreallocSettings struct { diff --git a/pkg/golinters/perfsprint.go b/pkg/golinters/perfsprint.go index acaa3a522547..6fe315fdea4d 100644 --- a/pkg/golinters/perfsprint.go +++ b/pkg/golinters/perfsprint.go @@ -20,6 +20,7 @@ func NewPerfSprint(settings *config.PerfSprintSettings) *goanalysis.Linter { cfg[a.Name]["err-error"] = settings.ErrError cfg[a.Name]["errorf"] = settings.ErrorF cfg[a.Name]["sprintf1"] = settings.SprintF1 + cfg[a.Name]["strconcat"] = settings.StrConcat } return goanalysis.NewLinter( diff --git a/test/testdata/perfsprint.go b/test/testdata/perfsprint.go index 8799f8f1da89..ca2ae1db3124 100644 --- a/test/testdata/perfsprint.go +++ b/test/testdata/perfsprint.go @@ -29,7 +29,7 @@ func TestPerfsprint() { fmt.Sprint(ui) // want "fmt.Sprint can be replaced with faster strconv.FormatUint" fmt.Sprintf("%x", []byte{'a'}) // want "fmt.Sprintf can be replaced with faster hex.EncodeToString" fmt.Errorf("hello") // want "fmt.Errorf can be replaced with errors.New" - fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string addition" + fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string concatenation" fmt.Sprint("test", 42) fmt.Sprint(42, 42) diff --git a/test/testdata/perfsprint_custom.go b/test/testdata/perfsprint_custom.go index cf4e5ca9d15b..04de585b7eff 100644 --- a/test/testdata/perfsprint_custom.go +++ b/test/testdata/perfsprint_custom.go @@ -30,7 +30,7 @@ func TestPerfsprint2() { fmt.Sprint(ui) fmt.Sprintf("%x", []byte{'a'}) // want "fmt.Sprintf can be replaced with faster hex.EncodeToString" fmt.Errorf("hello") - fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string addition" + fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string concatenation" fmt.Sprint("test", 42) fmt.Sprint(42, 42)