From 0ec46c4fd22664c2a662827a46fe0338a87d09a7 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 29 Mar 2025 09:39:55 +0800 Subject: [PATCH] chore: update and streamline linting configuration and error formatting - Update `.golangci.yaml` to version 2 and streamline settings - Remove specific linters from `.golangci.yaml` configuration - Add exclusion and formatter settings to `.golangci.yaml` - Change error message formatting in `plugin.go` to lowercase - Use `strings.ReplaceAll` instead of `strings.Replace` for better readability and performance in `plugin.go` and `plugin_test.go` Signed-off-by: appleboy --- .golangci.yaml | 68 +++++++++++++++++++++++++++++--------------------- plugin.go | 8 +++--- plugin_test.go | 2 +- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 377f2f1..c01d3c7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,15 +1,9 @@ -run: - timeout: 5m +version: "2" linters: enable: - asciicheck - durationcheck - - errcheck - errorlint - - exportloopref - - gci - - gofmt - - goimports - gosec - misspell - nakedret @@ -19,24 +13,42 @@ linters: - revive - usestdlibvars - wastedassign - -linters-settings: - gosec: - # To select a subset of rules to run. - # Available rules: https://github.com/securego/gosec#available-rules - # Default: [] - means include all rules - includes: - - G102 - - G106 - - G108 - - G109 - - G111 - - G112 - - G201 - - G203 - perfsprint: - err-error: true - errorf: true - int-conversion: true - sprintf1: true - strconcat: true + settings: + gosec: + includes: + - G102 + - G106 + - G108 + - G109 + - G111 + - G112 + - G201 + - G203 + perfsprint: + int-conversion: true + err-error: true + errorf: true + sprintf1: true + strconcat: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/plugin.go b/plugin.go index 004f5e5..ea0d4c4 100644 --- a/plugin.go +++ b/plugin.go @@ -14,9 +14,9 @@ import ( ) var ( - errMissingHost = errors.New("Error: missing server host") - errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") - errCommandTimeOut = errors.New("Error: command timeout") + errMissingHost = errors.New("error: missing server host") + errMissingPasswordOrKey = errors.New("error: can't connect without a private SSH key or password") + errCommandTimeOut = errors.New("error: command timeout") envsFormat = "export {NAME}={VALUE}" ) @@ -55,7 +55,7 @@ type ( ) func escapeArg(arg string) string { - return "'" + strings.Replace(arg, "'", `'\''`, -1) + "'" + return "'" + strings.ReplaceAll(arg, "'", `'\''`) + "'" } func (p Plugin) hostPort(host string) (string, string) { diff --git a/plugin_test.go b/plugin_test.go index 125ab62..29682c3 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -638,7 +638,7 @@ func TestEnvOutput(t *testing.T) { } func unindent(text string) string { - return strings.TrimSpace(strings.Replace(text, "\t", "", -1)) + return strings.TrimSpace(strings.ReplaceAll(text, "\t", "")) } func TestPlugin_scriptCommands(t *testing.T) {