Skip to content

Commit

Permalink
Updated linters
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Nov 19, 2022
1 parent 95abc9b commit 8daeeb3
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
version: v1.50.1

- name: Build
run: go build -v .
Expand Down
96 changes: 23 additions & 73 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,32 @@ run:
- testing
- dist
linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
enable-all: true
disable:
- exhaustivestruct
- nosnakecase
- interfacer
- scopelint
- maligned
- varcheck
- golint
- structcheck
- deadcode
- decorder
- depguard
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gci
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goerr113
- gofmt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- ifshort
- importas
- ineffassign
- ireturn
- lll
- maintidx
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- revive
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- tenv
- testpackage
- typecheck
- unconvert
- unparam
- unused
- varcheck
- varnamelen
- rowserrcheck
- sqlclosecheck
- wastedassign
- whitespace
- wrapcheck
- funlen
- paralleltest
- gochecknoglobals
- thelper
- godox
- exhaustruct
- wsl
- gci
- gofmt
- gofumpt
- nolintlint
presets:
- bugs
- comment
Expand Down
2 changes: 1 addition & 1 deletion internal/config/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (

func ReadURLMapping(config *viper.Viper) (map[string]string, error) {
urlMappings := map[string]string{}
from, to := config.GetStringSlice("from"), config.GetStringSlice("to") // nolint: varnamelen
from, to := config.GetStringSlice("from"), config.GetStringSlice("to") //nolint: varnamelen

if len(from) > len(to) {
return nil, ErrNoToPair
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var defaultHTTPClient = http.Client{
},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
InsecureSkipVerify: true, //nolint: gosec
},
Proxy: http.ProxyFromEnvironment,
},
Expand All @@ -36,7 +36,7 @@ func MakeHTTPClient(proxy string) (*http.Client, error) {

httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
InsecureSkipVerify: true, //nolint: gosec
},
Proxy: http.ProxyURL(parsedURL),
}
Expand Down
6 changes: 4 additions & 2 deletions internal/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/assert"
)

const loggerResult = "this is test message"
const loggerFResult = "this is %s message"
const (
loggerResult = "this is test message"
loggerFResult = "this is %s message"
)

func TestGlobalLogPackage(t *testing.T) {
log.EnableOutput()
Expand Down
10 changes: 6 additions & 4 deletions internal/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/stretchr/testify/assert"
)

const testMessage = "this is test message"
const testFMessage = "this is %s message"
const prefix = " Test "
const (
testMessage = "this is test message"
testFMessage = "this is %s message"
prefix = " Test "
)

func TestPrefixedLogger(t *testing.T) {
log.EnableOutput()
Expand Down Expand Up @@ -75,7 +77,7 @@ func TestPrefixedLogger(t *testing.T) {
})

t.Run("custom output", testutils.LogTest(func(t *testing.T, output *bytes.Buffer) {
var buffer = &bytes.Buffer{}
buffer := &bytes.Buffer{}

logger := log.NewLogger(prefix, log.WithOutput(buffer))

Expand Down
10 changes: 6 additions & 4 deletions internal/mock/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"github.com/stretchr/testify/assert"
)

var mock1Body = `{"mock": "mock number 1"}`
var mock2Body = `{"mock": "mock number 2"}`
var mock3Body = `{"mock": "mock number 3"}`
var mock4Body = `{"mock": "mock number 4"}`
var (
mock1Body = `{"mock": "mock number 1"}`
mock2Body = `{"mock": "mock number 2"}`
mock3Body = `{"mock": "mock number 3"}`
mock4Body = `{"mock": "mock number 4"}`
)

var notFoundBody = "404 page not found\n"

Expand Down
2 changes: 1 addition & 1 deletion internal/ui/logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Logo(version string) string {
logo, _ := pterm.DefaultBigText.
WithLetters(
putils.LettersFromStringWithStyle("UN", pterm.NewStyle(pterm.FgRed)),
putils.LettersFromStringWithRGB("CORS", pterm.NewRGB(255, 215, 0)), // nolint: gomnd
putils.LettersFromStringWithRGB("CORS", pterm.NewRGB(255, 215, 0)), //nolint: gomnd
).
Srender()

Expand Down
1 change: 0 additions & 1 deletion internal/ui/logo_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:lll
package ui_test

import (
Expand Down
8 changes: 5 additions & 3 deletions internal/urlreplacer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ type mapping struct {
target *Replacer
}

type Factory struct { // nolint: revive
type Factory struct {
mappings []mapping
}

var ErrMappingNotFound = errors.New("mapping not found")
var ErrMappingNotSpecified = errors.New("you must specify at least one mapping")
var (
ErrMappingNotFound = errors.New("mapping not found")
ErrMappingNotSpecified = errors.New("you must specify at least one mapping")
)

func NewURLReplacerFactory(urlMappings map[string]string) (*Factory, error) {
if len(urlMappings) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion internal/urlreplacer/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func wildCardToRegexp(parsedPattern *url.URL) (*regexp.Regexp, int, error) {
}

func wildCardToReplacePattern(parsedPattern *url.URL) (string, int, error) {
var result = &strings.Builder{}
result := &strings.Builder{}
var count int

if _, err := fmt.Fprint(result, "${scheme}"); err != nil {
Expand Down
12 changes: 8 additions & 4 deletions internal/urlreplacer/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
"github.com/evg4b/uncors/pkg/urlx"
)

const httpScheme = "http"
const defaultHTTPPort = 80
const (
httpScheme = "http"
defaultHTTPPort = 80
)

const httpsScheme = "https"
const defaultHTTPSPort = 443
const (
httpsScheme = "https"
defaultHTTPSPort = 443
)

func NormaliseMappings(mappings map[string]string, httpPort, httpsPort int, useHTTPS bool) (map[string]string, error) {
processedMappings := map[string]string{}
Expand Down
12 changes: 8 additions & 4 deletions internal/urlreplacer/replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
"github.com/evg4b/uncors/pkg/urlx"
)

var ErrEmptySourceURL = errors.New("source url should not be empty")
var ErrEmptyTargetURL = errors.New("target url should not be empty")
var (
ErrEmptySourceURL = errors.New("source url should not be empty")
ErrEmptyTargetURL = errors.New("target url should not be empty")
)

var ErrInvalidSourceURL = errors.New("source url is invalid")
var ErrURLNotMached = errors.New("is not matched")
var (
ErrInvalidSourceURL = errors.New("source url is invalid")
ErrURLNotMached = errors.New("is not matched")
)

type hook = func(string) string

Expand Down
4 changes: 2 additions & 2 deletions internal/urlreplacer/replacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ var isSecureTestCases = []struct {
}

func TestReplacerIsSourceSecure(t *testing.T) {
var makeReplacer = func(source string) *urlreplacer.Replacer {
makeReplacer := func(source string) *urlreplacer.Replacer {
t.Helper()
replacer, err := urlreplacer.NewReplacer(source, "https://github.com")
if err != nil {
Expand All @@ -257,7 +257,7 @@ func TestReplacerIsSourceSecure(t *testing.T) {
}

func TestReplacerIsTargetSecure(t *testing.T) {
var makeReplacer = func(target string) *urlreplacer.Replacer {
makeReplacer := func(target string) *urlreplacer.Replacer {
t.Helper()
replacer, err := urlreplacer.NewReplacer("https://github.com", target)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

func main() {
pflag.StringSlice("to", []string{}, "Target host with protocol for to the resource to be proxy")
pflag.StringSlice("from", []string{}, "Local host with protocol for to the resource from which proxying will take place") // nolint: lll
pflag.StringSlice("from", []string{}, "Local host with protocol for to the resource from which proxying will take place") //nolint: lll
pflag.Int("http-port", defaultHTTPPort, "Local HTTP listening port")
pflag.Int("https-port", defaultHTTPSPort, "Local HTTPS listening port")
pflag.String("cert-file", "", "Path to HTTPS certificate file")
Expand Down

0 comments on commit 8daeeb3

Please sign in to comment.