Skip to content

Commit

Permalink
Rename gosprintfhostport to nosprintfhostport
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Apr 22, 2022
1 parent 6293bb4 commit a9b1541
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .golangci.example.yml
Expand Up @@ -1662,7 +1662,6 @@ linters:
- goprintffuncname
- gosec
- gosimple
- gosprintfhostport
- govet
- ifshort
- importas
Expand All @@ -1680,6 +1679,7 @@ linters:
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
Expand Down Expand Up @@ -1753,7 +1753,6 @@ linters:
- goprintffuncname
- gosec
- gosimple
- gosprintfhostport
- govet
- ifshort
- importas
Expand All @@ -1771,6 +1770,7 @@ linters:
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -83,6 +83,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.11.0
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
Expand Down Expand Up @@ -156,7 +157,6 @@ require (
github.com/spf13/afero v1.8.2 // 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
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.

@@ -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(
Expand Down
10 changes: 5 additions & 5 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -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().
Expand Down Expand Up @@ -536,6 +531,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/firefart/nonamedreturns"),

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).
Expand Down
@@ -1,4 +1,4 @@
//args: -Egosprintfhostport
//args: -Enosprintfhostport
package testdata

import (
Expand All @@ -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"))

Expand All @@ -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"
Expand Down

0 comments on commit a9b1541

Please sign in to comment.