Skip to content

build(deps): bump github.com/catenacyber/perfsprint from 0.2.0 to 0.3.0 #4157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,11 @@ linters-settings:
# Default: false
ignore-missing-subtests: true

perfsprint:
# Optimizes even if it requires an int or uint type cast.
# Default: true
int-conversion: false

prealloc:
# IMPORTANT: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/breml/errchkjson v0.3.6
github.com/butuzov/ireturn v0.2.1
github.com/butuzov/mirror v1.1.0
github.com/catenacyber/perfsprint v0.2.0
github.com/catenacyber/perfsprint v0.3.0
github.com/charithe/durationcheck v0.0.10
github.com/curioswitch/go-reassign v0.2.0
github.com/daixiang0/gci v0.11.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

9 changes: 9 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ var defaultLintersSettings = LintersSettings{
RequireSpecific: false,
AllowUnused: false,
},
PerfSprint: PerfSprintSettings{
IntConversion: true,
},
Prealloc: PreallocSettings{
Simple: true,
RangeLoops: true,
Expand Down Expand Up @@ -222,6 +225,7 @@ type LintersSettings struct {
NoLintLint NoLintLintSettings
NoNamedReturns NoNamedReturnsSettings
ParallelTest ParallelTestSettings
PerfSprint PerfSprintSettings
Prealloc PreallocSettings
Predeclared PredeclaredSettings
Promlinter PromlinterSettings
Expand Down Expand Up @@ -675,11 +679,16 @@ type NoLintLintSettings struct {
type NoNamedReturnsSettings struct {
ReportErrorInDefer bool `mapstructure:"report-error-in-defer"`
}

type ParallelTestSettings struct {
IgnoreMissing bool `mapstructure:"ignore-missing"`
IgnoreMissingSubtests bool `mapstructure:"ignore-missing-subtests"`
}

type PerfSprintSettings struct {
IntConversion bool `mapstructure:"int-conversion"`
}

type PreallocSettings struct {
Simple bool
RangeLoops bool `mapstructure:"range-loops"`
Expand Down
16 changes: 13 additions & 3 deletions pkg/golinters/perfsprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import (
"github.com/catenacyber/perfsprint/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewPerfSprint() *goanalysis.Linter {
a := analyzer.Analyzer
func NewPerfSprint(settings *config.PerfSprintSettings) *goanalysis.Linter {
a := analyzer.New()

var cfg map[string]map[string]any
if settings != nil {
cfg = map[string]map[string]any{
a.Name: {
"int-conversion": settings.IntConversion,
},
}
}

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
cfg,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
6 changes: 4 additions & 2 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
noLintLintCfg *config.NoLintLintSettings
noNamedReturnsCfg *config.NoNamedReturnsSettings
parallelTestCfg *config.ParallelTestSettings
perfSprintCfg *config.PerfSprintSettings
preallocCfg *config.PreallocSettings
predeclaredCfg *config.PredeclaredSettings
promlinterCfg *config.PromlinterSettings
Expand Down Expand Up @@ -202,8 +203,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
preallocCfg = &m.cfg.LintersSettings.Prealloc
parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
perfSprintCfg = &m.cfg.LintersSettings.PerfSprint
preallocCfg = &m.cfg.LintersSettings.Prealloc
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
promlinterCfg = &m.cfg.LintersSettings.Promlinter
reassignCfg = &m.cfg.LintersSettings.Reassign
Expand Down Expand Up @@ -712,7 +714,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle, linter.PresetTest).
WithURL("https://github.com/kunwardeep/paralleltest"),

linter.NewConfig(golinters.NewPerfSprint()).
linter.NewConfig(golinters.NewPerfSprint(perfSprintCfg)).
WithSince("v1.55.0").
WithLoadForGoAnalysis().
WithPresets(linter.PresetPerformance).
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/configs/perfsprint_int_conversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
perfsprint:
int-conversion: false
6 changes: 5 additions & 1 deletion test/testdata/perfsprint.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//golangcitest:args -Eperfsprint
package testdata

import "fmt"
import (
"fmt"
)

func TestPerfsprint() {
var (
Expand All @@ -26,6 +28,8 @@ func TestPerfsprint() {
fmt.Sprintf("%d", ui) // want "fmt.Sprintf can be replaced with faster strconv.FormatUint"
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.Sprint("test", 42)
fmt.Sprint(42, 42)
Expand Down
54 changes: 54 additions & 0 deletions test/testdata/perfsprint_int_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//golangcitest:args -Eperfsprint
//golangcitest:config_path testdata/configs/perfsprint_int_conversion.yml
package testdata

import (
"fmt"
)

func TestPerfsprint2() {
var (
s string
err error
b bool
i int
i64 int64
ui uint
)

fmt.Sprintf("%s", s) // want "fmt.Sprintf can be replaced with just using the string"
fmt.Sprint(s) // want "fmt.Sprint can be replaced with just using the string"
fmt.Sprintf("%s", err) // want "fmt.Sprintf can be replaced with err.Error()"
fmt.Sprint(err) // want "fmt.Sprint can be replaced with err.Error()"
fmt.Sprintf("%t", b) // want "fmt.Sprintf can be replaced with faster strconv.FormatBool"
fmt.Sprint(b) // want "fmt.Sprint can be replaced with faster strconv.FormatBool"
fmt.Sprintf("%d", i) // want "fmt.Sprintf can be replaced with faster strconv.Itoa"
fmt.Sprint(i) // want "fmt.Sprint can be replaced with faster strconv.Itoa"
fmt.Sprintf("%d", i64) // want "fmt.Sprintf can be replaced with faster strconv.FormatInt"
fmt.Sprint(i64) // want "fmt.Sprint can be replaced with faster strconv.FormatInt"
fmt.Sprintf("%d", ui)
fmt.Sprint(ui)
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.Sprint("test", 42)
fmt.Sprint(42, 42)
fmt.Sprintf("test")
fmt.Sprintf("%v")
fmt.Sprintf("%d")
fmt.Sprintf("%d", 42, 42)
fmt.Sprintf("%#d", 42)
fmt.Sprintf("value %d", 42)
fmt.Sprintf("val%d", 42)
fmt.Sprintf("%s %v", "hello", "world")
fmt.Sprintf("%#v", 42)
fmt.Sprintf("%T", struct{ string }{})
fmt.Sprintf("%%v", 42)
fmt.Sprintf("%3d", 42)
fmt.Sprintf("% d", 42)
fmt.Sprintf("%-10d", 42)
fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6)
fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
}