Skip to content

Commit 45d2e48

Browse files
dependabot[bot]ldez
authored andcommitted
build(deps): bump github.com/catenacyber/perfsprint from 0.2.0 to 0.3.0 (#4157)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent a54fabd commit 45d2e48

File tree

9 files changed

+96
-9
lines changed

9 files changed

+96
-9
lines changed

.golangci.reference.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,11 @@ linters-settings:
13781378
# Default: false
13791379
ignore-missing-subtests: true
13801380

1381+
perfsprint:
1382+
# Optimizes even if it requires an int or uint type cast.
1383+
# Default: true
1384+
int-conversion: false
1385+
13811386
prealloc:
13821387
# IMPORTANT: we don't recommend using this linter before doing performance profiling.
13831388
# For most programs usage of prealloc will be a premature optimization.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/breml/errchkjson v0.3.6
2828
github.com/butuzov/ireturn v0.2.2
2929
github.com/butuzov/mirror v1.1.0
30-
github.com/catenacyber/perfsprint v0.2.0
30+
github.com/catenacyber/perfsprint v0.3.0
3131
github.com/charithe/durationcheck v0.0.10
3232
github.com/curioswitch/go-reassign v0.2.0
3333
github.com/daixiang0/gci v0.11.2

go.sum

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

pkg/config/linters_settings.go

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ var defaultLintersSettings = LintersSettings{
104104
RequireSpecific: false,
105105
AllowUnused: false,
106106
},
107+
PerfSprint: PerfSprintSettings{
108+
IntConversion: true,
109+
},
107110
Prealloc: PreallocSettings{
108111
Simple: true,
109112
RangeLoops: true,
@@ -222,6 +225,7 @@ type LintersSettings struct {
222225
NoLintLint NoLintLintSettings
223226
NoNamedReturns NoNamedReturnsSettings
224227
ParallelTest ParallelTestSettings
228+
PerfSprint PerfSprintSettings
225229
Prealloc PreallocSettings
226230
Predeclared PredeclaredSettings
227231
Promlinter PromlinterSettings
@@ -675,11 +679,16 @@ type NoLintLintSettings struct {
675679
type NoNamedReturnsSettings struct {
676680
ReportErrorInDefer bool `mapstructure:"report-error-in-defer"`
677681
}
682+
678683
type ParallelTestSettings struct {
679684
IgnoreMissing bool `mapstructure:"ignore-missing"`
680685
IgnoreMissingSubtests bool `mapstructure:"ignore-missing-subtests"`
681686
}
682687

688+
type PerfSprintSettings struct {
689+
IntConversion bool `mapstructure:"int-conversion"`
690+
}
691+
683692
type PreallocSettings struct {
684693
Simple bool
685694
RangeLoops bool `mapstructure:"range-loops"`

pkg/golinters/perfsprint.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@ import (
44
"github.com/catenacyber/perfsprint/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
89
)
910

10-
func NewPerfSprint() *goanalysis.Linter {
11-
a := analyzer.Analyzer
11+
func NewPerfSprint(settings *config.PerfSprintSettings) *goanalysis.Linter {
12+
a := analyzer.New()
13+
14+
var cfg map[string]map[string]any
15+
if settings != nil {
16+
cfg = map[string]map[string]any{
17+
a.Name: {
18+
"int-conversion": settings.IntConversion,
19+
},
20+
}
21+
}
1222

1323
return goanalysis.NewLinter(
1424
a.Name,
1525
a.Doc,
1626
[]*analysis.Analyzer{a},
17-
nil,
27+
cfg,
1828
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1929
}

pkg/lint/lintersdb/manager.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
121121
noLintLintCfg *config.NoLintLintSettings
122122
noNamedReturnsCfg *config.NoNamedReturnsSettings
123123
parallelTestCfg *config.ParallelTestSettings
124+
perfSprintCfg *config.PerfSprintSettings
124125
preallocCfg *config.PreallocSettings
125126
predeclaredCfg *config.PredeclaredSettings
126127
promlinterCfg *config.PromlinterSettings
@@ -202,8 +203,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
202203
nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
203204
noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
204205
noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
205-
preallocCfg = &m.cfg.LintersSettings.Prealloc
206206
parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
207+
perfSprintCfg = &m.cfg.LintersSettings.PerfSprint
208+
preallocCfg = &m.cfg.LintersSettings.Prealloc
207209
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
208210
promlinterCfg = &m.cfg.LintersSettings.Promlinter
209211
reassignCfg = &m.cfg.LintersSettings.Reassign
@@ -712,7 +714,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
712714
WithPresets(linter.PresetStyle, linter.PresetTest).
713715
WithURL("https://github.com/kunwardeep/paralleltest"),
714716

715-
linter.NewConfig(golinters.NewPerfSprint()).
717+
linter.NewConfig(golinters.NewPerfSprint(perfSprintCfg)).
716718
WithSince("v1.55.0").
717719
WithLoadForGoAnalysis().
718720
WithPresets(linter.PresetPerformance).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
perfsprint:
3+
int-conversion: false

test/testdata/perfsprint.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//golangcitest:args -Eperfsprint
22
package testdata
33

4-
import "fmt"
4+
import (
5+
"fmt"
6+
)
57

68
func TestPerfsprint() {
79
var (
@@ -26,6 +28,8 @@ func TestPerfsprint() {
2628
fmt.Sprintf("%d", ui) // want "fmt.Sprintf can be replaced with faster strconv.FormatUint"
2729
fmt.Sprint(ui) // want "fmt.Sprint can be replaced with faster strconv.FormatUint"
2830
fmt.Sprintf("%x", []byte{'a'}) // want "fmt.Sprintf can be replaced with faster hex.EncodeToString"
31+
fmt.Errorf("hello") // want "fmt.Errorf can be replaced with errors.New"
32+
fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string addition"
2933

3034
fmt.Sprint("test", 42)
3135
fmt.Sprint(42, 42)
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//golangcitest:args -Eperfsprint
2+
//golangcitest:config_path testdata/configs/perfsprint_int_conversion.yml
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
)
8+
9+
func TestPerfsprint2() {
10+
var (
11+
s string
12+
err error
13+
b bool
14+
i int
15+
i64 int64
16+
ui uint
17+
)
18+
19+
fmt.Sprintf("%s", s) // want "fmt.Sprintf can be replaced with just using the string"
20+
fmt.Sprint(s) // want "fmt.Sprint can be replaced with just using the string"
21+
fmt.Sprintf("%s", err) // want "fmt.Sprintf can be replaced with err.Error()"
22+
fmt.Sprint(err) // want "fmt.Sprint can be replaced with err.Error()"
23+
fmt.Sprintf("%t", b) // want "fmt.Sprintf can be replaced with faster strconv.FormatBool"
24+
fmt.Sprint(b) // want "fmt.Sprint can be replaced with faster strconv.FormatBool"
25+
fmt.Sprintf("%d", i) // want "fmt.Sprintf can be replaced with faster strconv.Itoa"
26+
fmt.Sprint(i) // want "fmt.Sprint can be replaced with faster strconv.Itoa"
27+
fmt.Sprintf("%d", i64) // want "fmt.Sprintf can be replaced with faster strconv.FormatInt"
28+
fmt.Sprint(i64) // want "fmt.Sprint can be replaced with faster strconv.FormatInt"
29+
fmt.Sprintf("%d", ui)
30+
fmt.Sprint(ui)
31+
fmt.Sprintf("%x", []byte{'a'}) // want "fmt.Sprintf can be replaced with faster hex.EncodeToString"
32+
fmt.Errorf("hello") // want "fmt.Errorf can be replaced with errors.New"
33+
fmt.Sprintf("Hello %s", s) // want "fmt.Sprintf can be replaced with string addition"
34+
35+
fmt.Sprint("test", 42)
36+
fmt.Sprint(42, 42)
37+
fmt.Sprintf("test")
38+
fmt.Sprintf("%v")
39+
fmt.Sprintf("%d")
40+
fmt.Sprintf("%d", 42, 42)
41+
fmt.Sprintf("%#d", 42)
42+
fmt.Sprintf("value %d", 42)
43+
fmt.Sprintf("val%d", 42)
44+
fmt.Sprintf("%s %v", "hello", "world")
45+
fmt.Sprintf("%#v", 42)
46+
fmt.Sprintf("%T", struct{ string }{})
47+
fmt.Sprintf("%%v", 42)
48+
fmt.Sprintf("%3d", 42)
49+
fmt.Sprintf("% d", 42)
50+
fmt.Sprintf("%-10d", 42)
51+
fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
52+
fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6)
53+
fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
54+
}

0 commit comments

Comments
 (0)