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 <appleboy.tw@gmail.com>
This commit is contained in:
appleboy 2025-03-29 09:39:55 +08:00
parent 07c75984e5
commit 0ec46c4fd2
No known key found for this signature in database
3 changed files with 45 additions and 33 deletions

View File

@ -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$

View File

@ -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) {

View File

@ -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) {