From 692608e8c6acfe69634fd3bee638fcc8986b0a19 Mon Sep 17 00:00:00 2001 From: Ethan Leisinger Date: Wed, 23 Oct 2024 10:34:00 -0600 Subject: [PATCH] fix most linter warnings and errors --- .golangci.yaml | 39 +++++++++++++++++++-------------------- themepark.go | 32 +++++++++++++++++--------------- themepark_test.go | 4 ++-- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index cd2ae74..3651595 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,19 +1,23 @@ run: timeout: 3m - skip-files: - - httputil/header/header.go - - apps/app_name.go - - themes/theme_name.go - skip-dirs: [] linters-settings: - govet: - check-shadowing: false - golint: - min-confidence: 0 + depguard: + rules: + allow_repos: + allow: + - github.com/packruler/rewrite-body/handler + - github.com/packruler/rewrite-body/compressutil + - bytes + - context + - fmt + - net/http + - net/http/httptest + - regexp + - strconv + - strings + - testing gocyclo: min-complexity: 12 - maligned: - suggest-new: true goconst: min-len: 3 min-occurrences: 4 @@ -25,22 +29,13 @@ linters-settings: linters: enable-all: true disable: - - scopelint - - golint - - interfacer - - maligned - bodyclose - - goerr113 - wrapcheck - - maligned - - exhaustivestruct - testpackage - paralleltest - tparallel - - nosnakecase issues: exclude-use-default: false - max-per-linter: 0 max-same-issues: 0 exclude: - don't use an underscore in package name @@ -57,3 +52,7 @@ issues: - path: themepark.go linters: - exhaustruct + exclude-files: + - httputil/header/header.go + - apps/app_name.go + - themes/theme_name.go diff --git a/themepark.go b/themepark.go index b7028d6..cb04f29 100644 --- a/themepark.go +++ b/themepark.go @@ -92,7 +92,7 @@ func (config *Config) setDefaults() { } if config.Theme == "" || config.Theme == "base" { - config.Theme = fmt.Sprintf("%s-base", config.App) + config.Theme = config.App + "-base" } if config.Target == "" { @@ -100,23 +100,25 @@ func (config *Config) setDefaults() { } } -var bodyBasedAppsList []string = []string{ - "vuetorrent", - "qbittorrent", - "emby", - "jellyfin", - "radarr", - "prowlarr", - "sonarr", - "readarr", - "lidarr", - "whisparr", -} +func getBodyBasedAppsRegex() string { + bodyBasedAppsList := []string{ + "vuetorrent", + "qbittorrent", + "emby", + "jellyfin", + "radarr", + "prowlarr", + "sonarr", + "readarr", + "lidarr", + "whisparr", + } -var bodyBasedApps string = "(?i)" + strings.Join(bodyBasedAppsList, "|") + return "(?i)" + strings.Join(bodyBasedAppsList, "|") +} func (config *Config) getRegexTarget() string { - match, _ := regexp.Match(bodyBasedApps, []byte(config.App)) + match, _ := regexp.MatchString(getBodyBasedAppsRegex(), config.App) if match { return "" } diff --git a/themepark_test.go b/themepark_test.go index aaf4a49..e1c5c02 100644 --- a/themepark_test.go +++ b/themepark_test.go @@ -118,13 +118,13 @@ func TestServeHTTP(t *testing.T) { t.Run(test.desc, func(t *testing.T) { config := test.config - next := func(responseWriter http.ResponseWriter, req *http.Request) { + next := func(responseWriter http.ResponseWriter, _ *http.Request) { responseWriter.Header().Set("Content-Encoding", test.contentEncoding) responseWriter.Header().Set("Content-Type", test.contentType) responseWriter.Header().Set("Content-Length", strconv.Itoa(len(test.resBody))) responseWriter.WriteHeader(http.StatusOK) - _, _ = fmt.Fprintf(responseWriter, test.resBody) + _, _ = fmt.Fprintf(responseWriter, "%s", test.resBody) } rewriteBody, err := New(context.Background(), http.HandlerFunc(next), &config, "rewriteBody")