From ca43d96e6fafd27d1dc8c05d70b1344f1214b607 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 12:28:27 +0000 Subject: [PATCH 1/3] build(deps): bump github.com/catenacyber/perfsprint from 0.6.0 to 0.7.0 Bumps [github.com/catenacyber/perfsprint](https://github.com/catenacyber/perfsprint) from 0.6.0 to 0.7.0. - [Commits](https://github.com/catenacyber/perfsprint/compare/v0.6.0...v0.7.0) --- updated-dependencies: - dependency-name: github.com/catenacyber/perfsprint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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= From b370209e35d08b520d1f9761e0ecfca60bc6dae5 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 15 Feb 2024 13:31:26 +0100 Subject: [PATCH 2/3] chore: update implementation --- .golangci.reference.yml | 5 ++++- pkg/config/linters_settings.go | 2 ++ pkg/golinters/perfsprint.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) 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/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( From 9a3cc4331aa68c43103f9bf93f6a6681dc4acbc1 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 15 Feb 2024 13:36:42 +0100 Subject: [PATCH 3/3] chore: fix tests --- test/testdata/perfsprint.go | 2 +- test/testdata/perfsprint_custom.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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)