From adc78d336192f8d08cd51255eb0eb6d186c239ce Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Thu, 7 Apr 2022 07:31:08 -0400 Subject: [PATCH] Rename gosprintfhostport to nosprintfhostport --- .golangci.example.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- .../{gosprintfhostport.go => nosprintfhostport.go} | 4 ++-- pkg/lint/lintersdb/manager.go | 10 +++++----- .../{gosprintfhostport.go => nosprintfhostport.go} | 13 +++++++++---- 6 files changed, 21 insertions(+), 16 deletions(-) rename pkg/golinters/{gosprintfhostport.go => nosprintfhostport.go} (72%) rename test/testdata/{gosprintfhostport.go => nosprintfhostport.go} (87%) diff --git a/.golangci.example.yml b/.golangci.example.yml index 8bf89c562448..e88f18304b40 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -1660,7 +1660,6 @@ linters: - goprintffuncname - gosec - gosimple - - gosprintfhostport - govet - ifshort - importas @@ -1678,6 +1677,7 @@ linters: - nlreturn - noctx - nolintlint + - nosprintfhostport - paralleltest - prealloc - predeclared @@ -1751,7 +1751,6 @@ linters: - goprintffuncname - gosec - gosimple - - gosprintfhostport - govet - ifshort - importas @@ -1769,6 +1768,7 @@ linters: - nlreturn - noctx - nolintlint + - nosprintfhostport - paralleltest - prealloc - predeclared diff --git a/go.mod b/go.mod index 1aaba595cbf2..ce9acf3b395b 100644 --- a/go.mod +++ b/go.mod @@ -82,6 +82,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.10.1 github.com/ssgreg/nlreturn/v2 v2.2.1 + github.com/stbenjam/no-sprintf-host-port v0.1.0 github.com/stretchr/testify v1.7.1 github.com/sylvia7788/contextcheck v1.0.4 github.com/tdakkota/asciicheck v0.1.1 @@ -153,7 +154,6 @@ require ( github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cast v1.4.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/stbenjam/go-sprintf-host-port v0.0.1 github.com/stretchr/objx v0.1.1 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect diff --git a/go.sum b/go.sum index 46827be34af1..c32e20b92453 100644 --- a/go.sum +++ b/go.sum @@ -692,8 +692,8 @@ github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk= github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU= github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YEwQ0= github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I= -github.com/stbenjam/go-sprintf-host-port v0.0.1 h1:GIYVAMLV4f5WBe0NgilYOlmUYE2KYKJaf4teZbXKF7I= -github.com/stbenjam/go-sprintf-host-port v0.0.1/go.mod h1:zL9IPLqGeN2rek8FGf1SCvR90PPflm9wfrWaAHfB68I= +github.com/stbenjam/no-sprintf-host-port v0.1.0 h1:pnSetrEuD55O56B6OKROPSNwJtjUkjaiM+MDzuqNeG4= +github.com/stbenjam/no-sprintf-host-port v0.1.0/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/pkg/golinters/gosprintfhostport.go b/pkg/golinters/nosprintfhostport.go similarity index 72% rename from pkg/golinters/gosprintfhostport.go rename to pkg/golinters/nosprintfhostport.go index 4156922810d1..a63b9bb5f567 100644 --- a/pkg/golinters/gosprintfhostport.go +++ b/pkg/golinters/nosprintfhostport.go @@ -1,13 +1,13 @@ package golinters import ( - "github.com/stbenjam/go-sprintf-host-port/pkg/analyzer" + "github.com/stbenjam/no-sprintf-host-port/pkg/analyzer" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" ) -func NewGoSprintfHostPort() *goanalysis.Linter { +func NewNoSprintfHostPort() *goanalysis.Linter { a := analyzer.Analyzer return goanalysis.NewLinter( diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index c40e069c7865..1c69a1469000 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -421,11 +421,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithAlternativeNames(megacheckName). WithURL("https://github.com/dominikh/go-tools/tree/master/simple"), - linter.NewConfig(golinters.NewGoSprintfHostPort()). - WithSince("v1.46.0"). - WithPresets(linter.PresetStyle). - WithURL("https://github.com/stbenjam/go-sprintf-host-port"), - linter.NewConfig(golinters.NewGovet(govetCfg)). WithSince("v1.0.0"). WithLoadForGoAnalysis(). @@ -531,6 +526,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL("https://github.com/sonatard/noctx"). WithNoopFallback(m.cfg), + linter.NewConfig(golinters.NewNoSprintfHostPort()). + WithSince("v1.46.0"). + WithPresets(linter.PresetStyle). + WithURL("https://github.com/stbenjam/no-sprintf-host-port"), + linter.NewConfig(golinters.NewParallelTest()). WithSince("v1.33.0"). WithPresets(linter.PresetStyle, linter.PresetTest). diff --git a/test/testdata/gosprintfhostport.go b/test/testdata/nosprintfhostport.go similarity index 87% rename from test/testdata/gosprintfhostport.go rename to test/testdata/nosprintfhostport.go index c11e280b41a8..e298e5a637b8 100644 --- a/test/testdata/gosprintfhostport.go +++ b/test/testdata/nosprintfhostport.go @@ -1,4 +1,4 @@ -//args: -Egosprintfhostport +//args: -Enosprintfhostport package testdata import ( @@ -7,15 +7,18 @@ import ( ) func _() { - _ = fmt.Sprintf("gopher://%s/foo", net.JoinHostPort("foo", "80")) _ = fmt.Sprintf("postgres://%s:%s@127.0.0.1/%s", "foo", "bar", "baz") - _ = fmt.Sprintf("http://%s/foo", net.JoinHostPort("foo", "80")) + _ = fmt.Sprintf("http://api.%s/foo", "example.com") _ = fmt.Sprintf("http://api.%s:6443/foo", "example.com") - _ = fmt.Sprintf("http://api.%s/foo", "example.com") + _ = fmt.Sprintf("http://%s/foo", net.JoinHostPort("foo", "80")) + + _ = fmt.Sprintf("9invalidscheme://%s:%d", "myHost", 70) + + _ = fmt.Sprintf("gopher://%s/foo", net.JoinHostPort("foo", "80")) _ = fmt.Sprintf("telnet+ssl://%s/foo", net.JoinHostPort("foo", "80")) @@ -29,6 +32,8 @@ func _() { _ = fmt.Sprintf("telnet+ssl://%s:%d", "myHost", 23) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("weird3.6://%s:%d", "myHost", 23) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" + _ = fmt.Sprintf("https://user@%s:%d", "myHost", 8443) // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" _ = fmt.Sprintf("postgres://%s:%s@%s:5050/%s", "foo", "bar", "baz", "qux") // ERROR "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf"